The shell (bash) script doesn’t offer any data type with the variables. So we can’t specifically declare a variable of type boolean in shell scripts.
Advertisement
But, you can still use the variable like a boolean in shell scripts. Store a sample string “true” to a variable and match it with the if condition. This works similarly to boolean.
1 2 3 4 5 6 7 8 9 10 11 | #!/usr/bin/env bash # Assign a string to a variable var=true # Test the variable value if [ "$var" = 'true' ]; then echo "It's true" else echo "It's false" fi |
So, even if the shell script doesn’t offer the data types, but we can still use the normal variable with similar working.