【发布时间】:2014-06-28 19:18:43
【问题描述】:
我想打印控制台中给出的一些参数
但我想用整数给出的数字打印参数
declare -i I=2declare -i I=4
我想打印参数 2 和 4 我该怎么做
不使用以下 if 语句
if [ $I -eq 2 ]; then
echo $2
fi
我正在寻找的是这样的想法echo $($I) #first access $I, which is 4 and# then print $4, which is the 4th argument
【问题讨论】:
-
var -i I=2在 Unix shell 脚本中有效吗? -
对不起的意思是
declare -i I=2 -
使用间接扩展:
echo "${!I}" -
一些研究会有所帮助。这个问题在 Stack Overflow 上已经被问过(并回答了)很多次。