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

相关文章:

  • 2022-12-23
  • 2021-12-24
  • 2021-07-31
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2021-09-27
  • 2022-12-23
猜你喜欢
  • 2021-07-09
  • 2021-08-30
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案