Home > Back-end >  Bash error [: missing `]' when checking if file exists
Bash error [: missing `]' when checking if file exists

Time:04-17

I am getting the error [: missing ]'` when running the below line in bash.

if [ ! -f "$file"]; then
    echo "File not found!"
fi

CodePudding user response:

change

[ ! -f "$file"]

to

[ ! -f "$file" ]

Change summary: added space before ]

  • Related