Hi,
I am trying to create a bash script which will check if file exist then remove that file else do nothing. I have to do same process for three files in same script. I have written code for one file and trying to run it.
if [ -e /user1/abc/File1]
then
rm -r /user1/abc/File1
fi
When I run this code it gives me following error:
"line 7: syntax error: unexpected end of file"
Any help/suggestion will be very much appreciated on this error.
need a space before closing square bracket. Also remember to use the
```text
and
```
tags when posting code/code segments.
Also note that the -r flag is for directories (remove recursively), is this a directory you are trying to remove or a file. If it's a directory then you should test with the -d option not -e
if [ -e /user1/abc/File1 ]
then
rm /user1/abc/File1
fi
You could also use the -f option of rm (ignore noexistent files) and don't bother testing if the file exists:
rm -f /usr1/abc/File1
1 Like