Timeline for Test nested variables in a while loop
Current License: CC BY-SA 3.0
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Nov 18, 2017 at 11:10 | comment | added | B Layer | Wish I knew why someone downvoted this. Did I make an error? Or do you just take 'eval is evil' literally? | |
| Nov 17, 2017 at 14:03 | vote | accept | Radvansky | ||
| Nov 17, 2017 at 13:50 | comment | added | B Layer | The other answer is the better answer when it is applicable but it is applicable only for arithmetic evaluation. Within the double parens you can have integer arithmetic, logical, and bitwise operators (see the Arithmetic Evaluation section of man bash). If this doesn't apply to you you can often use eval safely if careful. You'll have to read up on it and decide what u want to do. (If only you are using/accessing the script then it's not too much of a concern.) Here's a nice site (the page has examples of "good" eval use): mywiki.wooledge.org/BashFAQ/048 | |
| Nov 17, 2017 at 10:17 | comment | added | Radvansky | Thank you for your answer, it fully works. However @fpmurphy1 provided a nice alternative which apparently doesn't pose the problems of eval. Both answers work in the scenario I provided, but yours was able to parse a more complex condition, ie: [[ $(iwconfig wlan0 | grep "ESSID:off") ]]. Would it be possible to use @fpmurphy1 method to test such conditions? From your answer I assume it would be better to avoid the eval if possible. | |
| Nov 17, 2017 at 6:08 | history | edited | B Layer | CC BY-SA 3.0 | added 10 characters in body |
| Nov 17, 2017 at 6:02 | history | edited | B Layer | CC BY-SA 3.0 | Missed some double quotes |
| Nov 17, 2017 at 5:56 | history | answered | B Layer | CC BY-SA 3.0 |