2014-02-10 26 views
1

我有在我传递的参数的数目bash脚本,并希望得到的索引参数指定如何从变量值在bash

#! /bin/bash 

index=$1 
echo "argument at index $1 is" $[$index] 

./temp.sh 3 1 2 5 6 
argument at index 3 is 3 

but I want output like 
argument at index 3 is 2 

回答

1

您可以使用indirect variable referencing

#! /bin/bash 

index="$1" 
echo "argument at index: $index is ${!index}" 

输出:(含您的命令行)

argument at index: 3 is 2