【发布时间】:2016-02-04 05:25:27
【问题描述】:
我刚刚开始在 Unix 中编写 if-else 语句。这是我最近写的一个简短的 Bash 脚本。我不断收到一个模棱两可的重定向错误,但我无法找出问题所在。
执行时,我收到以下错误消息:
stringComp: line 17: $str2: ambiguous redirect
stringComp: line 20: $str2: ambiguous redirect
stringComp: line 23: [: too many arguments
这是脚本:
str1="I like turtles"
str2="I want to be Iron Man"
if [ $str1 > $str2 ]
then
echo "The first string is longer than the second"
elif [ $str1 < $str2 ]
then
echo "The second string is longer than the first"
elif [ $str1 = $str2 ]
then
echo "Both strings are of equal length"
else
echo "Invalid argument"
fi
有什么建议可以在这里做什么吗?谢谢。
【问题讨论】:
标签: bash shell unix if-statement logic