How can I declare and use Boolean variables in a shell script?
Asked 07 September, 2021
Viewed 1.4K times
  • 53
Votes

I tried to declare a Boolean variable in a shell script using the following syntax:

variable=$false

variable=$true

Is this correct? Also, if I wanted to update that variable would I use the same syntax? Finally, is the following syntax for using Boolean variables as expressions correct?

if [ $variable ]

if [ !$variable ]

23 Answer