Skip to content

Latest commit

 

History

History
612 lines (509 loc) · 20.9 KB

condition.md

File metadata and controls

612 lines (509 loc) · 20.9 KB

Category: Condition

⬅️ Back to previous page

TOC

Modules

end_with

end_with.s

has

  • Usage: l.has <condition> <what>
  • Description:
    • Exit with 0 or 1. Check if command/function/alias/keyword/builtin or anything existed.
    • <condition> Valid value: command, function, alias, keyword, builtin, the
  • Since: 0.3.0
  • Bash: 4.0+
  • Status: tested
  • Test Cases: tests/modules/has.bats
  • Source Code: src/modules/has.bash

has.s

  • Usage: l.has.s <condition> <what>
  • Description:
    • Echo true or false to indicate that command/function/alias/keyword/builtin or anything existed.
    • <condition> Valid value: command, function, alias, keyword, builtin, the
  • Since: 0.3.0
  • Bash: 4.0+
  • Status: tested
  • Test Cases: tests/modules/has.s.bats
  • Source Code: src/modules/has.s.bash

has_not

has_not.s

if

  • Usage: l.if <condition> <then> [<else>]
  • Description:
    • The difference from shell builtin if is when condition function throw exception it will ended immediately.
    • <condition> can be function name, string and number. The function should return true/0 or false/1.
    • <then> and <else> must be function name. And <else> is optional.
    • When <condition> is true, <then> function will be invoked. Otherwise <else> will be invoked if it passed.
  • Since: 0.1.0
  • Bash: 4.0+
  • Status: tested
  • Test Cases: tests/modules/if.bats
  • Source Code: src/modules/if.bash

is_array

  • Usage: l.is_array <var_name>
  • Description: When the variable is array or associative array, it returns 0 (true). Otherwise it returns 1 (false). This function should never throw exception error.
  • Since: 0.3.0
  • Bash: 4.0+
  • Status: tested
  • Notice:
    • Only with bash 4.3, this function return 1 when the variable declared without initialization.
    • Because declare -p a shows declare: a: not found when declare -a a. It's a bug in bash 4.3.
  • Test Cases: tests/modules/is_array.bats
  • Source Code: src/modules/is_array.bash

is_array.s

  • Usage: l.is_array.s <var_name>
  • Description: When the variable is array or associative array, it prints true. Otherwise it prints false. And it always exit with code 0.
  • Dependent: is_array
  • Since: 0.3.0
  • Bash: 4.0+
  • Status: tested
  • Notice:
    • Only with bash 4.3, this function will echo false when the variable declared without initialization.
    • Because declare -p a shows declare: a: not found when declare -a a. It's a bug in bash 4.3.
  • Test Cases: tests/modules/is_array.s.bats
  • Source Code: src/modules/is_array.s.bash

is_bash

is_bash.s

is_dir

  • Usage: l.is_dir <path>
  • Description:
    • Detect <path> is whether a directory or not.
    • Return 0 (true) or 1 (false). This function should never throw exception error.
  • Since: 0.3.0
  • Bash: 4.0+
  • Status: tested
  • Test Cases: tests/modules/is_dir.bats
  • Source Code: src/modules/is_dir.bash

is_dir.s

  • Usage: l.is_dir.s <path>
  • Description:
    • Detect <path> is whether a directory or not.
    • This function always echo true or false and exit code always be 0.
  • Since: 0.3.0
  • Bash: 4.0+
  • Status: tested
  • Test Cases: tests/modules/is_dir.s.bats
  • Source Code: src/modules/is_dir.s.bash

is_executable

is_executable.s

is_executable_file

is_executable_file.s

is_exported

  • Usage: l.is_exported <var_name>
  • Description:
    • Check whether a shell variable is exported.
    • Return 0 (true) or 1 (false). This function should never throw exception error.
  • Since: 0.5.0
  • Bash: 4.0+
  • Status: tested
  • Test Cases: tests/modules/is_exported.bats
  • Source Code: src/modules/is_exported.bash

is_falsy

is_falsy.s

is_file

is_file.s

is_float

is_float.s

is_function

is_function.s

is_gnu_sed

is_integer

is_integer.s

is_link

is_link.s

is_number

is_number.s

is_readable

is_readable.s

is_truthy

  • Usage: l.is_truthy <str>
  • Description:
    • zero number and string "true" should be truthy.
    • Return 0 (true) or 1 (false). This function should never throw exception error.
  • Since: 0.3.0
  • Bash: 4.0+
  • Status: tested
  • Test Cases: tests/modules/is_truthy.bats
  • Source Code: src/modules/is_truthy.bash

is_truthy.s

is_tty_available

is_tty_available.s

is_ubuntu

  • Usage: l.is_ubuntu
  • Description:
    • Detect whether current os is Ubuntu or not.
    • Return 0 (true) or 1 (false). This function should never throw exception error.
  • Since: 0.5.0
  • Bash: 4.0+
  • Status: tested
  • Test Cases: tests/modules/is_ubuntu.bats
  • Source Code: src/modules/is_ubuntu.bash

is_undefined

is_writable

is_writable.s

not.s

  • Usage: l.not.s <condition>
  • Description: <condition> must be true or false. This function returns the opposite value.
  • Since: 0.3.0
  • Bash: 4.0+
  • Status: tested
  • Test Cases: tests/modules/not.s.bats
  • Source Code: src/modules/not.s.bash

not.s.p

start_with

  • Usage: l.start_with <string> <match>
  • Description:
    • Check if a string starts with given match string.
    • Return 0 (true) or 1 (false). This function should never throw exception error.
  • Since: 0.3.1
  • Bash: 4.0+
  • Status: tested
  • Test Cases: tests/modules/start_with.bats
  • Source Code: src/modules/start_with.bash

start_with.s

str_include

str_include.s

⬆️ Back up to TOC