Is

bool_is_false

Test whether a value represents a boolean false. Accepts: 1, false, no, off (case-insensitive).

Arguments

  • $1 (string): Value to test

Exit codes

  • 0: Value is a recognised false
  • 1: Value is not a recognised false

bool_is_true

Test whether a value represents a boolean true. Accepts: 0, y, true, yes, on (case-insensitive).

Arguments

  • $1 (string): Value to test

Exit codes

  • 0: Value is a recognised true
  • 1: Value is not a recognised true

bool

Evaluate a value or stdin as a boolean. When stdin is a pipe, reads one line and evaluates it. Otherwise evaluates $1. Thin wrapper around bool_is_true().

Arguments

  • $1 (string): Value to evaluate (ignored when stdin is a pipe)

Exit codes

  • 0: Value is truthy
  • 1: Value is falsy or empty

bool_is_valid

Test whether a value is any recognised boolean representation. Accepts: 0, 1, true, false, yes, no, on, off (case-insensitive).

Arguments

  • $1 (string): Value to test

Exit codes

  • 0: Value is a valid boolean
  • 1: Value is not a valid boolean

var_is_set

Test whether a variable is set and non-empty.

Arguments

  • $1 (string): Value to test

Exit codes

  • 0: Value is set and non-empty
  • 1: Value is unset or empty

var_is_unset

Test whether a variable is unset.

Arguments

  • $1 (string): Value to test

Exit codes

  • 0: Value is unset
  • 1: Value is set (even if empty)

var_is_empty

Test whether a variable is set but empty.

Arguments

  • $1 (string): Value to test

Exit codes

  • 0: Value is set and empty
  • 1: Value is unset or non-empty

var_is_blank

Test whether a variable is unset or empty.

Arguments

  • $1 (string): Value to test

Exit codes

  • 0: Value is unset or empty
  • 1: Value is set and non-empty

var_is_global

Test whether a variable is exported (global).

Arguments

  • $1 (string): Variable name

Exit codes

  • 0: Variable is exported
  • 1: Variable is not exported

var_is_local

Test whether a variable is a local (non-exported) variable.

Arguments

  • $1 (string): Variable name

Exit codes

  • 0: Variable is local
  • 1: Variable is not local

is_array

Test whether a name refers to an indexed array variable.

Arguments

  • $1 (string): Variable name

Exit codes

  • 0: Variable is an indexed array
  • 1: Variable is not an indexed array

is_command

Test whether a name resolves to a command in PATH or as a builtin/function.

Arguments

  • $1 (string): Command name

Exit codes

  • 0: Command exists
  • 1: Command does not exist

is_in_path

Test whether a name exists as an executable file in PATH. Unlike is_command, this does not match shell functions, aliases, or builtins — only external binaries found on disk. Walks PATH entries directly using [ -x ] rather than relying on command -v or type.

Arguments

  • $1 (string): Command name

Exit codes

  • 0: Executable found in PATH
  • 1: Not found in PATH or not executable

is_function

Test whether a name is a defined shell function.

Arguments

  • $1 (string): Name to test

Exit codes

  • 0: Name is a function
  • 1: Name is not a function

is_builtin

Test whether a name is a shell builtin.

Arguments

  • $1 (string): Name to test

Exit codes

  • 0: Name is a builtin
  • 1: Name is not a builtin

is_keyword

Test whether a name is a shell reserved keyword (e.g. if, while, case).

Arguments

  • $1 (string): Name to test

Exit codes

  • 0: Name is a keyword
  • 1: Name is not a keyword

is_alias

Test whether a name is a defined alias. Note: aliases are not inherited by subshells or non-interactive shells. In a non-interactive script context this will almost always return false unless the alias was defined in the same shell session or sourced file. Useful for interactive shells and sourced library testing.

Arguments

  • $1 (string): Name to test

Exit codes

  • 0: Name is an alias
  • 1: Name is not an alias (or shell is non-interactive)

is_interactive

Test whether the shell is running interactively.

Exit codes

  • 0: Shell is interactive
  • 1: Shell is not interactive

is_root

Test whether the current process is running as root (EUID 0).

Exit codes

  • 0: Running as root
  • 1: Not running as root

is_sourced

Test whether the current script is being sourced rather than executed. Bash-only; behaviour on other shells is undefined.

Exit codes

  • 0: Script is sourced
  • 1: Script is being executed directly

var_is_one_of

Test whether a value is one of an allowed set of values.

Example

var_is_one_of "${ENV}" dev staging prod

Arguments

  • $1 (string): The value to check
  • ... (string): Allowed values (all arguments after $1)

Exit codes

  • 0: Value is in the set; 1 Value is not in the set

var_exactly_one_set

Test whether exactly one of the given values is non-empty. Useful for validating mutually exclusive options.

Example

var_exactly_one_set "${opt_a}" "${opt_b}" "${opt_c}"

Arguments

  • ... (string): Values to test (at least two required)

Exit codes

  • 0: Exactly one non-empty; 1 Zero or more than one non-empty