【发布时间】:2012-07-21 18:08:09
【问题描述】:
我的 if 语句没有正常工作,我不明白为什么。
这就是我所拥有的
for LINE in $(cat someFile.txt)
do
inst=$(echo $LINE | awk -F, '{print $4}')
echo $inst # To verify is displaying correctly
if [ $inst == "UP" ]
then
echo "Program skips this when $inst is UP"
elif [ $inst == "DN" ]
then
echo "Program skips this when $inst is DN"
fi
done
当我在 IF 语句中使用-eq 时,程序会显示这个UP^M: 0403-009 The specified number is not valid for this command.
有什么想法吗??
编辑。找到答案:
由于某种原因,程序在末尾添加了一个返回字符。
在获取列值后添加:inst=$(echo $inst | tr -d '\r') 可以解决问题。
【问题讨论】:
-
您是否将脚本从窗口机器转移到了 unix 机器?在这种情况下,
dos2unix your_script_file可能会对您有所帮助。 -
它显示什么,您希望它显示什么?
-
@LucM:不,没有从 Windows 机器转移它
-
@beny23:程序在行尾添加了一个返回字符,这就是为什么它从来不是“UP”或“DN”
标签: shell unix scripting if-statement ksh