Hi
How can I check if the path exist or not?
echo "Enter path:";
read my_path;
##I should check whether my_path exists or not....
Hi
How can I check if the path exist or not?
echo "Enter path:";
read my_path;
##I should check whether my_path exists or not....
if [ -d $my_path ]
then
echo "path exist"
fi
or
[[ -d $my_path ]] && echo "path exist"
thanks
How can I change this to oppsosite.
I mean, if path doesnt exist, echo...
[[ -d $my_path ]] && echo "path exist"
Code:
if [ -d $my_path ] ;then
echo "path exist"
else
echo "path doesn't exist"
fi
You should read man test and the definition of path, see example:
$ test -e /test/dir1/foo.bar && echo Path OK || echo Path OK
Path OK
$ test -d /test/dir1/foo.bar && echo Path OK || echo Path NOK
Path NOK #that's wrong , the path exist , however it's not a directory (-d).