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