700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > syntax error near unexpected token `then'

syntax error near unexpected token `then'

时间:2018-08-21 07:16:35

相关推荐

syntax error near unexpected token `then'

#!/bin/bash

clear

function test

{

if[$1 -eq "root"]&&[$2 -eq "123456"]

then

echo "Right"

else

echo "Wrong"

fi

}

test root 123456

----------------------------

上面这个程序我执行时,报这个错误,刚接触shell,没想到它的语法这么……不说了,在网上找个原因,贴出正确的格式,并总结要注意的几点

=======================

#!/bin/bash

clear

function test

{

if [ $1-eq"root" ] && [ $2-eq"123456" ]

then

echo "Right"

else

echo "Wrong"

fi

}

test root 123456

==========================

总结:

1.if后要有空格

2.[] 中括号的开头和结尾要有空格!

3. [ $1-eq"root" ]中括号中的$1和-eq和"root"之间没有空格!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。