I'm trying to create script where user will give path to some file, and script will check if file exists and do some stuff... I've wrote this code:
read -p "Enter path: " $path
#check if path is not empty string
if [ -z $path ]
then
echo "path is empty string"
exit
fi
#check if file exist
if [ ! -f $path ]
then
echo "file doesnt exists"
fi
my problem is with secound condition - if I change $path
with some string everything is OK, but when I enter path via variable it is always "file doesnt exists" I was trying with
if [ ! -f `$path` ]
but if file doesnt have execute permission result is fail too. Can someone help me fix above code? :)
EDIT sorry, I meant -z
and -f
not double -z
condition
-z
test twice, you might want-e
to check if the file exists in the second test condition? – HBruijn Nov 8 '13 at 11:29-e
was correct, I was trying with-f
but if file was without execute permission i get error. – Krystian Nov 8 '13 at 11:35