Problems with getting or to work in a while loop
Hi,
I'm having trouble with my while loop, I can get it to work with one test, but not when I try to use an 'or'. Here's the script: Code:
#!/bin/bash Code:
$ ./while_loop.sh Code:
#!/bin/bash Many thanks, c_henry |
Hi,
try a logical AND: Code:
while [ "$input" != "Q" -a "$input" != "q" ]; do |
Perfect! Really appreciate the quick reply.
Many thanks, c_henry |
You're welcome.
|
On a side note, you may wish to use the prompt (-p) option to read, rather than a separate echo:
Code:
read -p "Enter a char [Q or q to exit]: " input |
User-prompts are usually better handled this way:
Code:
while true; do |
If user input is the first thing to happen at the beginning of each loop one might even consider:
Code:
while read -p "Enter a char [Q or q to exit]: " input; do |
All times are GMT -5. The time now is 12:21 AM. |