从字符串转换

基本类型 / 布尔类型

#bash has no parser for "true": compare the text
strValue1="true"
[[ "$strValue1" == "true" ]] && boolValue1=true || boolValue1=false
#boolValue1 is true

#,, lowers the letters, so the case does not matter
strValue2="TRUE"
[[ "${strValue2,,}" == "true" ]] && boolValue2=true || boolValue2=false
#boolValue2 is true

#-n is true for any text that is not empty, even for "false"
strValue3="false"
[[ -n "$strValue3" ]] && boolValue3=true || boolValue3=false
#boolValue3 is true

#"0" and "1" go through arithmetic: (( )) is true for a non-zero number
strValue4="0"
(( strValue4 )) && boolValue4=true || boolValue4=false
#boolValue4 is false

echo "boolValue1 is $boolValue1"
echo "boolValue2 is $boolValue2"
echo "boolValue3 is $boolValue3"
echo "boolValue4 is $boolValue4"