I am trying to read a file if file exist in a folder. But when I use if-then-else statement to check file exists or not, this error will occur. syntax error: unexpected end of file
I wrote script in centos7. I have tried in many ways to fix this error such as, removing square brackets, adding spaces and removing semi-columns. Still i couldn't find any solution.
flag="0"
path="/home/abc/file.txt"
if [ -f $path ]; then
flag="1"
echo "file exists"
else
echo "file could't find"
fi
I expect to print set flag as "1" if file exists and print "file could't find" if file doesn't exist.