Need help numbering my arguments
I have to write a program that precedes each argument with the line number.
while [ "$#" -ne 0 ] do echo $# :"$1" shift done This is what I have but the numbering is in reverse order ]$ prargs a b c d 4 :a 3 :b 2 :c 1 :d This is my output, I have tried different things but nothing works |
Hello LBP74, welcome to LQ,
your shift command decrements the number of arguments. And this are your linenumbers, decremented from 4 down to 1. You could as an alternative set a variable which you increment in each step of the loop. this would work: Code:
#!/bin/bash |
Quote:
i=1 while [ "$#" -ne 0 ] do echo $i :"$1" i=$((i + 1)) shift done ~ I just had to put in a variable to help with the counting of the lines! |
All times are GMT -5. The time now is 12:37 AM. |