Bash: using tests in a case structure
I am trying to simplify a series of loops by using a case structure.
This is for an optional exercise in my Linux class. I am new to Linux, bash, and programming in general. The case structure is not a requirement for the project, just something I wanted to try. Code:
var1=0 Is something like this possible in case structure? I have tried several variations and keep getting errors. |
It can be done, using the fact that bash does arithmetic evaluation of the pattern expressions and taking care to order the cases:
Code:
#!/bin/bash |
Thanks for the help. I got my script to work. I think it looks a lot cleaner then the bunch of nested ifs and loops.
This is the full script that works. Code:
#!/bin/bash Code:
case 1 in Thanks again for the help. |
1 is arithmetic true.
To see how it relates to the $(( ... )) case "patterns", run this command at the command prompt: var=3; echo $(( var1 < 4 )) |
All times are GMT -5. The time now is 07:41 PM. |