3

I'm trying to write a grub2 bootloader script but if statements always evaluate to true:

if [ -s blabla ] ; then set zzz0="1" ; fi
if [ ! -s blabla ] ; then set zzz1="1" ; fi

set TEST_VAR=foo

if [ "x${TEST_VAR}" = "xfoo" ] ; then set zzz2="1" ; fi
if [ "x${TEST_VAR}" = "xbar" ] ; then set zzz3="1" ; fi

if [ $TEST_VAR = foo ] ; then set zzz4="1" ; fi
if [ $TEST_VAR = bar ] ; then set zzz5="1" ; fi

So, after running this script, I see all zzz (zzz0, zzz1, zzz2, zzz3, zzz4, zzz5)variables set to 1. What am I doing wrong?

Thanks, Johnny

4

1 回答 1

0
if [ ! "${myvar}" = "" ]; then
   (lines here)
else
   (lines here)
fi

if [ "${myvar}" = "fred" ]; then
   (lines here)
else
   (lines here)
fi
于 2016-05-08T12:38:05.103 回答