I'm writing a short bash script to find if a file exists in a directory or not. Here is the script:
#!/bin/bash
> oldFiles.txt
files=$(grep ' jane ' ../data/list.txt | cut -d ' ' -f 3)
for f in $files; do
f=~$f
if [ -e $f ]; then
echo $f Found
echo $f>>oldFiles.txt
else
echo $f Not found
fi
done
Three relevant file names are found by the grep and searched over in the for loop. It appears, however, that every time my script runs the if command, it comes back False
regardless of whether the file exists or not. Please see the results of the script, followed by test -e
for each of the individual files, followed by a list of the files in the relevant directory. Also posted below is the referenced list.txt
file.
001 jane /data/jane_profile_07272018.doc
002 kwood /data/otherfile.doc
003 pchow /data/pfile.doc
004 janez /data/zfile.doc
005 jane /data/jane_pic_07282018.jpg
006 kwood /data/kwood.jpg
007 pchow /data/pchow.jpg
008 jane /data/jane_contact_07292018.csv
009 kwood /data/kwfile.csv
010 pchow /data/p2file.csv
I know what I'm missing has to be simple, but what is it?