Gene Heskett wrote at 12:04 -0400 on Jul 21, 2010:
 > Greetings all;
 > 
 > My catchup script seems to be working with 2 exceptions, first being that I 
 > am not getting any emails from it, so I installed dnsmasq to see if that 
 > fixes that.
 > 
 > 2nd, each pass through my catchup script loop elicits an error warning from 
 > the main script:
 > 
 > ./flush.sh: line 173: [: !=: unary operator expected
 > 
 > from that script:
 > # or are we running as flush.sh
 > 
 > if [ $0 == "./flush.sh" ] || [ $0 == "${MYDIR}/flush.sh" ] || [ $0 == 
 > "flush.sh" ]; then

== is a bash-ism.  Get in the habit of using = for posix compliance.
You'll thank yourself when you might have to run a script on a system
that doesn't use bash for sh(1) (bsd's, solaris).

"Always" put quotes around vars ("$foo", "$0", etc.) since vars
can contain strings with spaces confusing test(1) (aka [).

You don't need quotes around literals that you have written
("./flush.sh" in your case above).  So in '[ $0 == "./flush.sh" ]',
you have your quoting backwards (with respect to defensive script
writing).


 >         # we don't want amflush to disconnect or ask questions
 >         if [ `/bin/ls /dumps` != "" ] ; then  <-------------------line 173
 >                 echo "Backup script running amflush -bf $CONFIGNAME " |tee -
 > a >> $LOG

Same deal (use quotes) for back-tick expressions (`cmd` or $(cmd)).
And that's your problem.  Looks like `ls /dumps` is providing empty
output.

example:

if [ `echo 1 2` = 1 ]; then echo y; else echo n; fi
[: 1: unexpected operator

 or

bash -c 'if [ `echo -n` != "" ]; then echo y; else echo n; fi'
bash: [: !=: unary operator expected


if [ "`echo 1 2`" = 1 ]; then echo y; else echo n; fi
n


Reply via email to