| ResidentBiscuit (2214) | ||||
Ok not really C++ here, but I have this shell script assignment that I can't get to work. Just takes some input and throws it into some variables right now. Anyway, it has to loop back to the beginning using a while loop if there was a mistake. I can't get the condition to work at all. Just spits out errors everytime.
That while condition has been through every different way to do it that I can find, and I get the same type of message of
every time. No idea what I'm doing and I can't seem to find any documentation on how the condition is supposed to be here for while loops here. | ||||
|
|
||||
| naraku9333 (919) | |||
Try
note the space between the brackets. | |||
|
Last edited on
|
|||
| ResidentBiscuit (2214) | |
| Wow, I'm not at my machine with linux on it, but does the space really matter?? I saw this nowhere in my searching for answers -_- | |
|
|
|
| naraku9333 (919) | |
| I'm not experienced in shell scripting but the examples I found searching all had spaces and here http://tldp.org/LDP/abs/html/loops1.html in example 11-14 it states the space is necessary because they are test brackets. | |
|
|
|
| Aramil of Elixia (772) | |
| he removed the quotes around the variable bro and actually space shouldnt matter but I dont see why you have two [] sets | |
|
|
|
| slumpers (14) | |
|
Space does matter, since [[ and ]] are reserved keywords in BASH. [[ is different from single bracket [ in that [ is a system command ( /bin/[ which happens to take a ] as its last arguement ). While [ is almost completely portable, it supports far less in terms of what it can do, you are basically limited to the -eq -ne -lt -le etc type of comparisons, instead of == != < <= etc. Only the BASH and Korn shell support double brackets. | |
|
|
|
| ResidentBiscuit (2214) | |
|
What do the -eq, etc flags mean? I can assume -eq means equal to, -ne means not equal to, but the other two I don't know and I can't seem to find documentation on it anywhere. EDIT: I actually found out why it wasn't working. I was running it as "sh adduser", not "bash adduser" -_- This is why tutorials suck and documentation is the way to go. Anywho, my conditional doesn't seem to be checking correctly as if I type in "y" for the done variable, it still continues to loop through. | |
|
Last edited on
|
|
| slumpers (14) | ||
It worked fine for me.
Try encapsulating $done in { brackets like this: while [[ ${done} != "y" ]] Also it wouldn't hurt to see what your done variable is actually holding at the end of the loop for test purposes echo "\$done = \"${done}\""Edit: Those are the old fashion comparison tags from sh. -lt is less than, -le is less than or equal to. There is also -gt, -ge for greater than, -z for null and -n for not null. http://tldp.org/LDP/abs/html/comparison-ops.html | ||
|
Last edited on
|
||
| ikbendeman (1) | |
|
see 'man bash' also chmod +x /path/to/script ...better yet, use csh instead of bash. | |
|
|
|
| Aramil of Elixia (772) | |
| whats csh | |
|
|
|
| ResidentBiscuit (2214) | |
| I've thought about installing csh to play around with it because it seems fun, but haven't gotten to it yet. | |
|
|
|
| kbw (5374) | |
|
Don't use csh (or rather tcsh) for scripts. http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/ | |
|
|
|