【发布时间】:2011-10-16 08:40:48
【问题描述】:
我有一个循环创建一组变量,如 DISK1、DISK2...,其中变量名称末尾的数字由循环创建,然后加载设备名称的路径。现在我想在另一个循环中使用这些变量来执行一个 shell 命令,但是该变量没有将其内容提供给 shell 命令。
for (( counter=1 ; counter<=devcount ; counter++))
do
TEMP="\$DISK$counter"
# $TEMP should hold the variable name of the disk, which holds the device name
# TEMP was only for testing, but still has same problem as $DISK$counter
eval echo $TEMP #This echos correctly
STATD$counter=$(eval "smartctl -H -l error \$DISK$counter" | grep -v "5.41" | grep -v "Joe")
eval echo \$STATD$counter
done
【问题讨论】:
-
预期输出?实际输出?
-
输出无关紧要,因为这个问题是关于功能的