So I'm trying to check if a file exists or not and then the script is supposed to do something if it does. The problem I'm having is actually getting it to recognize that something is actually there.
if [ -e /temp/file.txt ]; then
echo "file found!"
sudo cp -r temp/* extra
else
echo "file not found! Creating new one..."
./create.sh
fi
below is an example of the files in the directory I'm testing. they are clearly there, but for some reason I can't get the script to see that. what am I doing wrong?
nima@mkt:/docs/text$ ls -a temp
. .. more file.txt file2.txt
You are using absolute paths in your test while you should be using relative paths:
if [ -e ./temp/file.txt ]; then
/temp/file.txt
vs /docs/text/temp/file.txt
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With