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.
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.
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.
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.
censored@censored:~/Desktop/progstuff$ bash whileloop.sh
First name:
test
Last name:
mctest
Login name:
testm
User ID:
1
Group ID:
01
Create home dir?[y/n]
n
Name: test mctest
Login name: testm
UID: 1
Group ID: 01
Want home dir? n
Is this correct?[y/n]
y
censored@censored:~/Desktop/progstuff$
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.