First thing: bash is whitespace sensitive. That means this is no good:
You want:
Code:
if [ ! -f $file1 ]
12345678901234567890
Notice, a space at position 3,5,7, and 17. Those all MUST be there. If you use an editor with syntax highlighting for shell scripts (eg, vim), it will be slightly easier to notice that.
But also your syntax is missing some things. Try this:
Code:
#!/bin/bash
echo "Enter Name of the first file:"
read file1
echo $file1
if [ ! -f $file1 ]; then
echo "Sorry, file does not exist."
exit 1
fi
Originally Posted by
TaiL
fixed it. But does anyone understand this error?
"[!: command command not found
Because your whitespace was wrong. The ! is right up against [, meaning [! was taken as a single token.