我有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
答案 0 :(得分:1)
您可以使用indirect variable referencing:
#! /bin/bash
index="$1"
echo "argument at index: $index is ${!index}"
OUTPUT:(使用您的命令行)
argument at index: 3 is 2