当前位置: 技术问答>linux和unix
shell编程中if的使用问题
来源: 互联网 发布时间:2017-01-20
本文导语: 本帖最后由 chen861201 于 2011-11-29 17:17:36 编辑 代码如下是按照鸟哥书上写的: read -p "please input your choice:(Y/N)" yn echo $yn if [ "$yn"=="n" ]||[ "$yn"=="N" ] then echo "oh,interrupt" exit 0 else echo "ok,continu...
read -p "please input your choice:(Y/N)" yn
echo $yn
if [ "$yn"=="n" ]||[ "$yn"=="N" ]
then
echo "oh,interrupt"
exit 0
else
echo "ok,continue"
exit 0
fi
终端输出总是第一个:
root@zhou:/scripts# sh sh05.sh
please input your choice:(Y/N)y
y
oh,interrupt
root@zhou:/scripts# sh sh05.sh
please input your choice:(Y/N)n
n
oh,interrupt
root@zhou:/scripts#
搞了一个下午了 不知道是哪里出了问题,我用的是ubuntu的os!!!
|
sh -x sh05.sh看真相
|
#!/bin/bash
read -p "please input your choice:(Y/N)" yn
echo $yn
if [ "$yn" = "n" ] || [ "$yn" = "N" ]
then
echo "oh,interrupt"
exit 0
else
echo "ok,continue"
exit 0
fi
一个=,另外要间隔好。