我在那里我试图打印出命令行arguments.to脚本测试脚本test.sh,但如预期bash命令行代替循环
`#!/bin/bash
for((i=1;i<"$#";i++)) do
printf "Position %s of argumentArray has %s \n", $i $(($i))
done`
(我的想法如下不起作用是,(())会做导致数学计算$ 1 $ 2等)同样没有
for((i=1;i<"$#";i++)) do
printf "Position %s of argumentArray has %s \n", $i $"$(eval echo $i)"
done
都给出了作为放时如运行如下
./test.sh first second third
Position 1 of argumentArray has 1
Position 1 of argumentArray has 2
Position 1 of argumentArray has 3
代替
Position 1 of argumentArray has first
Position 1 of argumentArray has second
Position 1 of argumentArray has third
我面临着同样的问题
for((i=1;i<="$#";i++))
do
case "$($i)" in
.......
情况下的计算结果为1,2 3等中传递的实际参数的insted的。
请帮我理解我错了。
感谢它的工作。完全忘记arays 我继续做。 ' 对于((i = 1; i <“$#”; i ++)) str = $(echo $(eval echo \ $$(echo $ i))) echo $ str printf“Position% s的batchProcessArray具有%s \ n“,$ i”$ str“ done ' 但您的答案是最佳解决方案。再次感谢。 –