Reputation: 11
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?
Upvotes: 1
Views: 468
Reputation: 506
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
Upvotes: 2
Reputation: 67831
-f
checks if the path exists and is a file
-d
checks if the path exists and is a directory
Upvotes: 2