shell if else 用法 syntax error near unexpected token `then'
1. ?錯誤
?
?
#!/bin/bash
platform=$1
if[?"$platform" = "ibmaix64" ]
then
? ? ? echo "$platform"
else
? ? ?echo "hello ooo"
fi
?
Error : ?syntax error near unexpected token `then'
原因: ??條件語句 [ 符號的兩邊都要留空格
?
if??[??$platform = "winx64" ]-----------------------right ? 綠色標記為空格
if[ ?$platform = "winx64" ]-----------------------wrong
if ?[$platform = "winx64" ]-----------------------wrong
?
2. 總結
?
?
2.1 空格
?
a.定義變量時, =號的兩邊不可以留空格
b.if語句 [ 符號的兩邊都要留空格
c.字符串比較, =兩邊要留空格
?
d. if 和then 在同一行 要加;
?
?
2.2 ?if 語句
?
?
#!/bin/sh
a=10
b=20
if [ $a == $b ]
then
? ?echo "a is equal to b"
fi
#!/bin/sh
a=10
b=20
if [ $a == $b ]
then
? ?echo "a is equal to b"
else
? ?echo "a is not equal to b"
fi
#!/bin/sh
a=10
b=20
if [ $a == $b ]
then
? ?echo "a is equal to b"
elif [ $a -gt $b ]
then
? ?echo "a is greater than b"
elif [ $a -lt $b ]
then
? ?echo "a is less than b"
else
? ?echo "None of the condition met"
fi
?
總結
以上是生活随笔為你收集整理的shell if else 用法 syntax error near unexpected token `then'的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: FFMPEG学习(一)---【命令行】采
- 下一篇: 用lua扩展你的Nginx(整理)