日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

shell if else 用法 syntax error near unexpected token `then'

發(fā)布時(shí)間:2024/2/28 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 shell if else 用法 syntax error near unexpected token `then' 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1. ?錯(cuò)誤

?

?

#!/bin/bash
platform=$1

if[?"$platform" = "ibmaix64" ]
then
? ? ? echo "$platform"

else

? ? ?echo "hello ooo"

fi

?

Error : ?syntax error near unexpected token `then'

原因: ??條件語(yǔ)句 [ 符號(hào)的兩邊都要留空格

?

if??[??$platform = "winx64" ]-----------------------right ? 綠色標(biāo)記為空格


if[ ?$platform = "winx64" ]-----------------------wrong
if ?[$platform = "winx64" ]-----------------------wrong

?

2. 總結(jié)

?

?

2.1 空格

?

a.定義變量時(shí), =號(hào)的兩邊不可以留空格


b.if語(yǔ)句 [ 符號(hào)的兩邊都要留空格


c.字符串比較, =兩邊要留空格

?

d. if 和then 在同一行 要加;

?

?

2.2 ?if 語(yǔ)句

?

?




#!/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

?

總結(jié)

以上是生活随笔為你收集整理的shell if else 用法 syntax error near unexpected token `then'的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。