I am using a optional variable BUILD_X
flag to decide whether to build X based on user input.
BUILD_X=true
while getopts "B:" option; do
case "$option" in
B) BUILD_X=$OPTARG;;
esac
done
if (( $BUILD_X == true )); then
body
fi
I am observing that even if I give BUILD_X false from the terminal as an input to script, it still executes the body. Where am I going wrong ?
false
is simply the string"false"
and does not have a boolean value.getopts "B"
and if that is true then setX_BUILD=""
; then in your conditional you can simply sayif [[ "$X_BUILD" ]]; then
if [[ "$BUILD_X" == true ]]
works but (( )) round brackets are not working ? I don't understand why because both can be used for comparisions(( ... ))
is mathematical context, it works fine for numbers but this is a string.