> How can I assign boolean value to a varible and test it later: > > if [ $b ] ; then echo b is true! ; fi > if [ !$b ] ; then echo b is false! ; fi > the above code will say that b is both true & false no matter what > value I give to b: 0,1, true & false.
man test — the contents of b are not parsed, it just checks whether it's set to something or not:
$ b=
$ if [ "$b" ] ; then echo empty string = true > else echo empty string = false; fi empty string = false
$ b=something
$ if [ "$b" ] ; then echo non-empty string = true > else echo non-empty string = false; fi non-empty string = true
/* era */