for loop for a particular range of arguments
I am writing a scripts which involves for loop. I want to make use of arguments passed to scripts ranging from 2nd to last.
I tried to use below Quote:
Quote:
Quote:
Please help. -Ravi |
You can try the shift statement to loop trough all the positional parameters. Before the loop save the first one, then cycle trough the others, e.g.
Code:
my_dir=$1 |
Hello,
A better option would be to use the positional parameter $@ in my opinion. Quote:
Code:
for i in $@ Kind regards, Eric EDIT: beaten by the newly baked mod :-) but with another solution. |
As an addon to Eric's solution, when dealing with positional parameters you can simply call the for loop like so:
Code:
for i |
The OP needs to cycle through positional parameters from the 2nd to the last one, so that your scripts need a little modification. Here is another solution with indirect reference:
Code:
for i in $(seq 2 $#) |
Hi,
Nice catch colucix, missed the fact about starting from the second parameter. Thanks for pointing it out and a solution. Kind regards, Eric |
Colucix,
Mate, Once again your solution worked! Many thanks.. _ravi |
Please mark as SOLVED once you have a solution.
|
All times are GMT -5. The time now is 07:39 AM. |