Unix Shell Scripting ifelse错误

时间:2015-12-16 11:32:48

标签: shell unix if-statement scripting

请帮助,此脚本在执行时会出现以下错误:

然后意外 找不到Str1 找不到Str2

#!/bin/ksh 

echo ">>Please press y or n :"
read Str

Str1="y"
Str2="n"
if[[$Str1 == $Str]];then
echo "You pressed Y."
elif[[$Str2 == $Str]]; then
echo "You pressed N."
else
echo "Error."
fi

1 个答案:

答案 0 :(得分:1)

你缺少空格。

#!/bin/ksh 

echo ">>Please press y or n :"
read Str

Str1="y"
Str2="n"
if [[ $Str1 == $Str ]]; then
    echo "You pressed Y."
elif [[ $Str2 == $Str ]]; then
    echo "You pressed N."
else
    echo "Error."
fi