Reputation: 1633
I was checking whether a file exists or not but i get error with the following code
filename="a.txt"
if [ -s $filename ] ; then
echo "exists"
else
echo "not exists"
fi
It gives the error [: 116: Illegal number
What could be the problem?
Upvotes: 0
Views: 1789
Reputation: 36827
You have to use -f
:
filename="a.txt"
; touch $filename
; echo $filename
if [ -f "$filename" ] ; then
echo "exists"
else
echo "not exists"
fi
-s
is to check that "FILE exists and is a socket".
Notes:
touch
sentence to ensure the file exists.echo $filename
sentence to ensure he var content."
to ensure no space or special chars inside $filename
.References:
Upvotes: 1