Sponsored By

Sign in to follow this  
shanenin

Loop Script

Recommended Posts

I think i have copied this script exactly as printed in my book, but it keeps failing

[email protected] shane $ cat scripts/loop
#!/bin/bash
x=0
while [ $x -lt 10 ]
do
  echo $x
  x=`echo "$X + 1" | bc`
done
[email protected] shane $ ./scripts/loop
0
(standard_in) 1: parse error
./scripts/loop: line 3: [: -lt: unary operator expected

Share this post


Link to post
Share on other sites

Typo. 'x' is capitalized on the sixth line.

Edited by jcl

Share this post


Link to post
Share on other sites

thanks. I can see debugging programs being a huge undertaking. I have trouble finding them with just three lines of code ;)

Share this post


Link to post
Share on other sites
thanks. I can see debugging programs being a huge undertaking. I have trouble finding them with just three lines of code  ;)

:)

By the way, if your book doesn't mention it, that could be rewritten to use shell arithmetic expansion:

#!/bin/bash
x=0
while [ $x -lt 10 ]
do
   echo $x
   x=$(($x + 1))
done

or even:

#!/bin/bash
x=0
while [ $x -lt 10 ]
do
   echo $((x++))
done

Not that I recommend deviating from the book.

Share this post


Link to post
Share on other sites

what is -lt (is that like NE or !=)

while [ $x -lt 10 ]

Not that I recommend deviating from the book.

an why should you suggest a better way.. :D

thanks

Share this post


Link to post
Share on other sites

yep..:)

sorry with this font I thought it was (one)t and I could not figure out what that stood for..

bash is confusing to me that way.. im used to < or <= .. this lt or ne and so on alwyas cates me off guard.

thanks..

Edited by iccaros

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this