Donnerstag, 16. Februar 2012

Freitag, 10. Februar 2012

Bash if statement

The Bash if statement is a bit funny. Say for every files-i.txt, there should be a files-i.dat.
This example can be used to filter out files that dont have the corresponding .dat file present.


for i in files-*txt
do
if [ ! -e ${i/txt/dat} ]
then
echo $i
fi
done


Note the spaces after and before the opening and closing hard bracket. Also note that "then" is on its own line.