multiple if condition in a bash script
Hi,
I've a question concerning multiple if 'conditions' in bash. My code looks as follows: Code:
#!/bin/bash 11, 18. But it doesn't do. Does somebody know how to do that? Best, grima |
Why not use a case statement: 'case $i in 7|11|18) echo "Welcome $i times";; esac;'?
|
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
|
Hi and welcome to LQ!
Try this: Code:
#!/bin/bash |
If you only need to match exact number strings, I second colucix's recommendation for a case statement. They're almost always more efficient than if tests.
Code:
#!/bin/bash Code:
#!/bin/bash http://mywiki.wooledge.org/BashFAQ/031 http://mywiki.wooledge.org/ArithmeticExpression And two other minor points: 1) You don't need a step operator in brace expansion if you're just counting by ones anyway. 2) Many scripters also feel that it's better to place the "do/then" keywords on the same line as the "for/while/until/if" keywords, as they are not separate commands but are paired with the opening keyword to bracket the test/input string. Putting them together on one line thus helps to better visually separate the outside block from the inside block. Scripting With Style |
All times are GMT -5. The time now is 07:22 PM. |