【发布时间】:2015-08-31 01:09:49
【问题描述】:
脚本:
#!/bin/bash
for SID in db1 db2 db3 db4
do
"$SID"_fs=$(
df -k
| grep "$SID\/data"
| tr -s ' '
| cut -d' ' -f6
| awk '{print substr($0,length($0),1)}'
| sort
| tail -1);
echo "$SID"_fs
done
./test_sm.sh: line 11: db1_fs=7: command not found
db1_fs
./test_sm.sh: line 11: db2_fs=7: command not found
db2_fs
./test_sm.sh: line 11: db3_fs=3: command not found
db3_fs
./test_sm.sh: line 11: db4_fs=2: command not found
db4_fs
变量设置为正确的值,但最终的“回声”没有给我变量的值(这是我需要的)。它反而给了我变量名。
【问题讨论】:
-
为了将来参考,您的示例不需要包含该命令替换的复杂性以使您的问题有意义。额外的噪音会让你更难理解问题并给出好的答案。
标签: bash shell variables for-loop sh