【发布时间】:2012-09-19 21:48:30
【问题描述】:
我正在尝试基于 $i 创建一个变量
i=1
line="one two three four five six"
while [[ $i -lt 3 ]]; do
set string$i=`echo $line | cut -d" " -f1-3`
echo $string$i
do_stuff_here
done
当我这样做时,我得到以下输出
1
预期的输出是
one two three
事实上,当我回显 $String1 时……我得到了预期的输出……所以它的存储正确。 我知道它是我调用 $string$1 的方式......但我尝试了各种引号/括号,但它不起作用。谁能告诉我如何调用我的变量?
【问题讨论】:
-
$string$1是$string$i的拼写错误吗? -
@chepner 是的……谢谢
标签: shell variables set ksh typeset