【发布时间】:2013-07-29 07:15:34
【问题描述】:
#!/bin/sh
b=( a b c d )
count=1
for a in ${b[@]}; do
example_$count=$a # how do I declare this variable "example_$count"
echo example_$count; # and how do I echo it
(( count++ ))
done
我需要的是这样的:
$example_1=a
$example_2=b
$example_3=c
$example_4=d
【问题讨论】:
-
为什么要这样做?为什么不只使用数组?例如,
$example_1将对应于${b[0]}。