Other Help Topics :: Cond statements, BASH



Is the DSL version of BASH stripped down? I haven't been able to get conditional statements working (e.g., if/then).
No, they work.  The version of bash is 2.x if memory serves.  Perhaps you weren't using that or there's some kind of scripting error?

EDIT: packages section shows 2.05b

Quote (^thehatsrule^ @ Sep. 08 2007,16:09)
No, they work.  The version of bash is 2.x if memory serves.  Perhaps you weren't using that or there's some kind of scripting error?

EDIT: packages section shows 2.05b

I'm using the same version, 2.05b.  Here's an example out of O'Reilly, with the result.  

dsl@box:~$ if {23 == 23}; then echo "okay"; fi
bash: {23: command not found

I'm not sure why curly braces were used in that example. I can't recall ever seeing tests done that way.

Any of these should work:
if [ 23 == 23 ]; then echo "okay"; fi
if [ 23 -eq 23 ]; then echo "okay"; fi
if test 23 == 23 ; then echo "okay"; fi
if test 23 -eq 23 ; then echo "okay"; fi
test 23 == 23 && echo "okay"
test 23 -eq 23 && echo "okay"
[ 23 == 23 ] && echo "okay"
[ 23 -eq 23 ] && echo "okay"

== is used for string or math comparison
-eq is apparently used for integers only

Quote (mikshaw @ Sep. 08 2007,22:43)
I'm not sure why curly braces were used in that example. I can't recall ever seeing tests done that way.

Any of these should work:
if [ 23 == 23 ]; then echo "okay"; fi
if [ 23 -eq 23 ]; then echo "okay"; fi
if test 23 == 23 ; then echo "okay"; fi
if test 23 -eq 23 ; then echo "okay"; fi
test 23 == 23 && echo "okay"
test 23 -eq 23 && echo "okay"
[ 23 == 23 ] && echo "okay"
[ 23 -eq 23 ] && echo "okay"

Actually, I tried all types of braces with the same result.  In your listed examples, only the "if test ...." worked....seems to be looking for a command following "if"....

With "if test" I didn't need any braces:

if test 23 == 23; then echo "ok"; fi

Next Page...
original here.