Results 1 to 2 of 2
I can't seem to find the correct syntax here. So I know how to do a for loop but how do I do an if statement in there or a ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 06-01-2012 #1Just Joined!
- Join Date
- Jun 2004
- Posts
- 9
For and While loops via command line
I can't seem to find the correct syntax here. So I know how to do a for loop but how do I do an if statement in there or a while statement. For example, I work in storage and our controllers run linux if I want to do a test using a customer python script I can do the following to reset ports on a specific node
for i in `seq 4`; do xcli.py fc_port_reset fc_port=1:fc_port:4:$i; done
However what if I want to make that 4 a variable and go all the way to 9? How do I do multiple variables as well as make a statement that says don't go past 9. I know logically I would do the following. But how would I express them in a command line loop?
int i = 1;
int x=4;
while x < 10; do xcli.py fc_port_reset fc_port=1:fc_port
:i;if i < 5 i++ else i=1; x++; done
Any help would be appreciated.
- 06-02-2012 #2Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,685
Hi,
I don't understand where an if is necessary, at least based upon what you say you want. if you want to go to 9, and not go past 9, then just do `seq 1 9`.
or if you want to make it a variable:
x=9
for i in `seq 1 $x`; do
but if you don't use $x again elsewhere, why do you want it to be a variable?
perhaps you should spell out exactly what you want your script to do.


Reply With Quote
