How do you check if any file (the user chooses) exists in a certain place?
$org
is a variable that I chose to set a path
if [ -e $org/$1]
then
echo "Do you want to overwrite"
exit 1
Do I use the if statement or getopts?
-f
checks if the path exists and is a file
-d
checks if the path exists and is a directory
-f
only detects regular files. It won't detect special files like device files or named pipes. It also won't match dead symlinks.
Commented
Jul 13, 2013 at 12:12
There should be a space between $org/$1
and ]
.
Try this:
if [ -e "$org/$1" ]; then
echo "Do you want to overwrite"
fi
More information here: http://tldp.org/LDP/abs/html/fto.html
-e "$org/$1"
works fine.
Commented
Jul 13, 2013 at 11:55
$org/$1
and]
. The correct form isif [ -e $org/$1 ]
. Take a look at my answer.