user3507952
user3507952

Reputation: 1

Assign Command line arguments to a variable in for loop in Unix

I have the following bash code:

for (( i=4; i<=$var; ))
do
    temp=`echo $i`
done

I need to assign the command line argument stored in $4 to the variable temp which is not happening.

Upvotes: 0

Views: 258

Answers (1)

that other guy
that other guy

Reputation: 123410

Given a variable i=4 you can get the value of $4 using ${!i}:

set -- foo bar baz thisOne etc
i=4
echo "${!i}"  

This prints the fourth positional parameter, thisOne.

Upvotes: 1

Related Questions