SHTK_BOOL_CHECK(3)
SHTK_BOOL_CHECK(3) Library Functions Manual SHTK_BOOL_CHECK(3)

shtk_bool_checkConverts a string to a boolean value

shtk_import bool

shtk_bool_check value [error_message]

The shtk_bool_check function takes the string value and returns the corresponding boolean value according to shell conventions.

shtk_bool_check returns 0 for any value representing truth. These include the strings ‘yes’ and ‘true’, including any variations in their capitalization, and the integer number ‘1’.

shtk_bool_check returns 1 for any value representing falsehood. These include the strings ‘no’ and ‘false’, including any variations in their capitalization, and the integer number ‘0’.

local verbose=no
# Parse flags to see if verbose mode is enabled and set verbose=yes.

if shtk_bool_check "${verbose}"; then
    # Print messages.
fi

shtk_bool_check prints the error given in error_message and exits the shell with non-zero if the value does not represent a valid boolean value. If error_message is not provided, a default message is printed.

shtk(3), shtk_bool(3)

shtk_bool_check first appeared in shtk 1.4.

November 5, 2014 Debian