我有一個循環創建了一組變量,如DISK1,DISK2 ...其中變量名稱末尾的數字由循環創建,然後加載了一個設備名稱的路徑。現在我想在另一個循環中使用這些變量來執行shell命令,但該變量不會將其內容提供給shell命令。Bash腳本使用Bash變量作爲參數執行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
預期輸出?實際產出? –
輸出是無關緊要的,因爲這個問題是關於功能 – sdproto