#!/bin/bashclearfunction test{if[$1 -eq "root"]&&[$2 -eq "123456"]thenecho "Right"elseecho "Wrong"fi}
test root 123456
----------------------------
上面這個程序我執行時,報這個錯誤,剛接觸shell,沒想到它的語法這么……不說了,在網上找個原因,貼出正確的格式,并總結要注意的幾點
=======================
#!/bin/bashclearfunction test{if [ $1-eq"root" ] && [ $2-eq"123456" ]thenecho "Right"elseecho "Wrong"fi}
test root 123456
==========================
總結:
1.if后要有空格
2.[] 中括號的開頭和結尾要有空格!
3. [ $1-eq"root" ]中括號中的$1和-eq和"root"之間沒有空格!
新聞熱點
疑難解答