常见错误

控制流 / 条件语句 / if/else 语句

latitude=45

#[[ 和 ]] 是单词:两侧都需要空格
#if [[$latitude == 0]]; then  #<- Error: "[[45: command not found"

#== 两侧没有空格时,条件就成了一个字符串 "45==0",
#而非空字符串为真
[[ $latitude==0 ]] && noSpaces=true || noSpaces=false
#noSpaces is true

[[ $latitude == 0 ]] && withSpaces=true || withSpaces=false
#withSpaces is false

#[[ ]] 中的 > 比较文本:"10" 排在 "9" 之前
[[ 10 > 9 ]] && asText=true || asText=false
#asText is false
(( 10 > 9 )) && asNumbers=true || asNumbers=false
#asNumbers is true

#赋值时 = 两侧没有空格
#latitude = 0  #<- Error: "latitude: command not found"

echo "noSpaces is $noSpaces"
echo "withSpaces is $withSpaces"
echo "asText is $asText"
echo "asNumbers is $asNumbers"