我有一些bash代码(抱歉格式化,Stack Overflow不起作用):
read -p "Start server and create configuration files (y or n)? : " startserver
if [ $startserver = "y" ]
then java -Xmx1024M -jar craftbukkit.jar -o true
elif [ $startserver = "n" ]
then exit 0
else invalid;
fi
它生成应该说“无效!”当我输入y或n以外的东西时。当输入中没有空格时,它会这样做。如果我输入一个空格,我会收到以下错误:
/home/snuggles08/Documents/CraftBukkit Installer.sh: line 5: [: =: unary operator expected
/home/snuggles08/Documents/CraftBukkit Installer.sh: line 7: [: =: unary operator expected
当文本有空格时,我收到以下错误:
/home/snuggles08/Documents/CraftBukkit Installer.sh: line 5: [: too many arguments
/home/snuggles08/Documents/CraftBukkit Installer.sh: line 7: [: too many arguments
为什么会这样?