Chinaunix

标题: shell编程,if then的问题 [打印本页]

作者: madao2007    时间: 2011-12-14 17:40
标题: shell编程,if then的问题
vi test04.sh
#!bin/bash


echo "Press y to continue"
read yn
if ["$yn"="y"]; then
        echo "script is running..."
else
        echo "STOP!"
fi


执行的结果:
Press y to continue
y
test04.sh: line 6: [y=y]: command not found
STOP!

请教一下!
作者: chenyx    时间: 2011-12-14 17:42
本帖最后由 chenyx 于 2011-12-14 17:46 编辑

[]与"$yn"="y"之间要有空格,要写成if [ "$yn" = "y" ]; then
作者: juruqiang    时间: 2011-12-14 19:46
{:3_189:}
作者: taojie2000    时间: 2011-12-14 20:56
好几个这样的问题了  空格
作者: defcon    时间: 2011-12-15 08:50
恩,木有加空格
作者: denifears    时间: 2011-12-15 14:33

作者: madao2007    时间: 2011-12-18 20:07
谢谢楼上的各位  小弟刚刚接触Linux,需要注意的问题很多。希望以后多关照




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2