Bash script - Infinite loop caused by a logical OR operator
Hello everyone. After a few hours trying to debug and searching LQ.org and Google and nothing I decided to post so someone could point me somewhere.
Let's get to the point, here's the code: Code:
freespacecd() { First time the loop goes $MULTISESSAO is evaluated true and $VAZIO is evaluated true and second time and so it's the opposite: $MULTISESSAO is now true and $VAZIO is false. I have no ideas anymore. I also tried without with single square brackets "[ ... ]" but it didn't work either. Any idea? |
You're not testing for TRUE and FALSeE, but rather for the literal strings "yes" and "no".
This aside, the trick is to insert extra echo statements to confirm the values of variables at different points in the program. |
Ok, sorry for the bad question. What I meant was: "is there anything wrong with the condition formation?". Its syntax is right to me and I think for you too since you said nothing about it... Thanks for the answer.
|
The conditional syntax looks fine to me (and bash should give an error message if it's not), but I think there is a problem with the cut statement you use:
Code:
| cut -c24-27 |
Problem solved. I seems that while doesn't support multiple conditions. Here's the resulting code:
Code:
freespacecd() { |
Use -o inside [[...]] instead of ||. Use || to separate two commands, where the second command is executed when the first one is successful.
|
I'm confused now. Now that you said to use -o I researched and that's quote from the Advanced Bash-Scripting Guide:
Quote:
Quote:
Skuzye |
Quote:
|
Yes, && only runs the second statement if the first succeeds and || runs the second statement if the first fai
I usually use them like this: [ "$exp1" -a "$exp2" ] [[ "$exp1" ]] && [[ "$exp2" ]] [ "$exp1" -o "$exp2" ] [[ "$exp1" ]] || [[ "$exp2" ]] |
Quote:
I did: echo "*$VARIABLE*" and got: *no*. Thanks gnashley I understood it now. |
All times are GMT -5. The time now is 06:39 AM. |