Linux bash-if语句问题

Linux bash-if语句问题,linux,bash,if-statement,scripting,Linux,Bash,If Statement,Scripting,有人能帮我一下下面的IF语句吗 阅读-e-p“是否要立即重新启动?”:“-i”“重新启动” 如果我输入“是”,我将得到以下结果 = yes = yes = yes ... = yes 如果我输入“否”,我会得到以下信息: ./test.sh: line 7: no: command not found ./test.sh: line 10: no: command not found You have chosen to reboot later 有什么想法吗?您得到的输出与您键入的内容相同

有人能帮我一下下面的IF语句吗

阅读-e-p“是否要立即重新启动?”:“-i”“重新启动”

如果我输入“是”,我将得到以下结果

= yes
= yes
= yes
...
= yes
如果我输入“否”,我会得到以下信息:

./test.sh: line 7: no: command not found
./test.sh: line 10: no: command not found
You have chosen to reboot later

有什么想法吗?

您得到的输出与您键入的内容相同:

yes = 'yes'
要表示比较,应在if上使用括号。应该是:

if [ $REBOOT = 'yes' ] ; then
if [ $REBOOT = 'yes' ] ; then
   echo 'System will now reboot'
   shutdown -r now
else
   echo 'You have chosen to reboot later'
fi
另外,在没有另一个if的else上还有第二个条件。反正你也不需要它

总代码应为:

if [ $REBOOT = 'yes' ] ; then
if [ $REBOOT = 'yes' ] ; then
   echo 'System will now reboot'
   shutdown -r now
else
   echo 'You have chosen to reboot later'
fi

您得到的输出与您键入的相同:

yes = 'yes'
要表示比较,应在if上使用括号。应该是:

if [ $REBOOT = 'yes' ] ; then
if [ $REBOOT = 'yes' ] ; then
   echo 'System will now reboot'
   shutdown -r now
else
   echo 'You have chosen to reboot later'
fi
另外,在没有另一个if的else上还有第二个条件。反正你也不需要它

总代码应为:

if [ $REBOOT = 'yes' ] ; then
if [ $REBOOT = 'yes' ] ; then
   echo 'System will now reboot'
   shutdown -r now
else
   echo 'You have chosen to reboot later'
fi

您得到的输出与您键入的相同:

yes = 'yes'
要表示比较,应在if上使用括号。应该是:

if [ $REBOOT = 'yes' ] ; then
if [ $REBOOT = 'yes' ] ; then
   echo 'System will now reboot'
   shutdown -r now
else
   echo 'You have chosen to reboot later'
fi
另外,在没有另一个if的else上还有第二个条件。反正你也不需要它

总代码应为:

if [ $REBOOT = 'yes' ] ; then
if [ $REBOOT = 'yes' ] ; then
   echo 'System will now reboot'
   shutdown -r now
else
   echo 'You have chosen to reboot later'
fi

您得到的输出与您键入的相同:

yes = 'yes'
要表示比较,应在if上使用括号。应该是:

if [ $REBOOT = 'yes' ] ; then
if [ $REBOOT = 'yes' ] ; then
   echo 'System will now reboot'
   shutdown -r now
else
   echo 'You have chosen to reboot later'
fi
另外,在没有另一个if的else上还有第二个条件。反正你也不需要它

总代码应为:

if [ $REBOOT = 'yes' ] ; then
if [ $REBOOT = 'yes' ] ; then
   echo 'System will now reboot'
   shutdown -r now
else
   echo 'You have chosen to reboot later'
fi
可能的重复可能的重复可能的重复可能的重复