Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (4) </ [1] 2 3 4 >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Cond statements, BASH< Next Oldest | Next Newest >
jpeters Offline





Group: Members
Posts: 804
Joined: April 2006
Posted: Sep. 08 2007,19:00 QUOTE

Is the DSL version of BASH stripped down? I haven't been able to get conditional statements working (e.g., if/then).
Back to top
Profile PM 
^thehatsrule^ Offline





Group: Members
Posts: 3275
Joined: July 2006
Posted: Sep. 08 2007,20:09 QUOTE

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
Back to top
Profile PM 
jpeters Offline





Group: Members
Posts: 804
Joined: April 2006
Posted: Sep. 09 2007,01:23 QUOTE

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
Back to top
Profile PM 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Sep. 09 2007,02:43 QUOTE

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


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
jpeters Offline





Group: Members
Posts: 804
Joined: April 2006
Posted: Sep. 09 2007,02:52 QUOTE

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
Back to top
Profile PM 
15 replies since Sep. 08 2007,19:00 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (4) </ [1] 2 3 4 >/
reply to topic new topic new poll
Quick Reply: Cond statements, BASH

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code