常见错误

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

latitude=45

#[[ and ]] are words: they need spaces around them
#if [[$latitude == 0]]; then  #<- Error: "[[45: command not found"

#without spaces around == the condition is one string "45==0",
#and a string that is not empty is true
[[ $latitude==0 ]] && noSpaces=true || noSpaces=false
#noSpaces is true

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

#> inside [[ ]] compares text: "10" goes before "9"
[[ 10 > 9 ]] && asText=true || asText=false
#asText is false
(( 10 > 9 )) && asNumbers=true || asNumbers=false
#asNumbers is true

#an assignment has no spaces around =
#latitude = 0  #<- Error: "latitude: command not found"

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