i need to test the contents of a file if it exists, and to set a flag
for example
Code:
...
MYDIR="/home/fred/"
...
FLAG="NO"
if [ -e $MYDIR"FLAGFILE" -a `cat $MYDIR"FLAGFILE"` = "YES" ]; then
FLAG="YES"
fi
...
this generates an error if $MYDIR"FLAGFILE" (/home/fred/FLAGFILE in this example) does not exist. even though it shouldn't evaluate the second part of the boolean AND if the first part returns false.
I can do this with two test lines
Code:
...
MYDIR="/home/fred/"
...
FLAG="NO"
if [ -e $MYDIR"FLAGFILE" ]; then
if [ `cat $MYDIR"FLAGFILE"` = "YES" ]; then
FLAG="YES"
fi
fi
which works just fine but it obviously makes the script the test/s are in much longer.
Has anyone any hints on making the single liner version work? thanks