๐Ÿ“‚ system

system::commandExists

Check if the given command exists.

  • $1: command name as string: the command name to check.

Returns:

  • $?
    • 0 if the command exists
    • 1 otherwise.
if system::commandExists "command1"; then
  printf 'The command exists.'
fi

system::env

Get the list of all the environment variables. In pure bash, no need for env or printenv.

Returns:

  • RETURNED_ARRAY: An array with the list of all the environment variables.
system::env
for var in "${RETURNED_ARRAY[@]}"; do
  printf '%s=%s\n' "${var}" "${!var}"
done

This is faster than using mapfile on <(compgen -v).

system::exportTerminalSize

This function exports the terminal size.

Returns:

  • GLOBAL_COLUMNS: The number of columns in the terminal.
  • GLOBAL_LINES: The number of lines in the terminal.
system::exportTerminalSize
printf '%s\n' "The terminal has โŒœ${GLOBAL_COLUMNS}โŒ columns and โŒœ${GLOBAL_LINES}โŒ lines."

system::getNotExistingCommands

This function returns the list of not existing commands for the given names.

  • $@: command names as string: the list of command names to check.

Returns:

  • $?
    • 0 if there are not existing commands
    • 1 otherwise.
  • RETURNED_ARRAY: the list of not existing commands.
if system::getNotExistingCommands "command1" "command2"; then
  printf 'The following commands do not exist: %s' "${RETURNED_ARRAY[*]}"
fi

system::os

Returns the name of the current OS.

Returns:

  • RETURNED_VALUE: the name of the current OS: “darwin”, “linux” or “windows”.
system::os
local osName="${RETURNED_VALUE}"

system::getUndeclaredVariables

This function returns the list of undeclared variables for the given names.

  • $@: variable names as string: the list of variable names to check.

Returns:

  • $?
    • 0 if there are variable undeclared
    • 1 otherwise.
  • RETURNED_ARRAY: the list of undeclared variables.
if system::getUndeclaredVariables "var1" "var2"; then
  printf 'The following variables are not declared: %s' "${RETURNED_ARRAY[*]}"
fi

system::date

Get the current date in the given format.

  • $1: format as string: (optional) the format of the date to return (defaults to %(%F_%Hh%Mm%Ss)T).

Returns:

  • RETURNED_VALUE: the current date in the given format.
system::date
local date="${RETURNED_VALUE}"

This function avoid to call $(date) in a subshell (date is a an external executable).

Documentation generated for the version 0.20.345 (2024-08-14).