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"之间没有空格!

posted @ 2014-02-12 11:58  宫本峻淏-龙二  阅读(436)  评论(0编辑  收藏  举报