How to get / echo positional parameters index

anneranch

Active Member
Joined
Mar 16, 2019
Messages
223
Reaction score
43
Credits
2,078
I have this working and simple code to echo positional parameters VALUES

for i
do
echo "Argument = $i "
done

Here is the actual output from the scrip

Argument = --atleast-pkgconfig-version
Argument = 0.9.0



It does the job, but ...
I have been trying to figure out how to ADD an index to the echo output.

This does not work

cnt=1
for i
do
echo "Argument $cnt = $i "
((cnt++))
done

The current code does the job, the index would be just icing on the cake - like this:

Argument #1 = --atleast-pkgconfig-version
Argument #2 = 0.9.0


Any ideas ?
 

Members online


Top