| title | lib_console – lib-bash |
|---|---|
| permalink | /lib/lib_console/ |
Include for console support.
Usage:
MY_PATH="$(realpath "${BASH_SOURCE[0]}")"
SCRIPT_DIR="$(dirname "${MY_PATH}")"
readonly MY_PATH
readonly SCRIPT_DIR
readonly LIB_BASH_DIR="${SCRIPT_DIR}/lib_bash"
source "${LIB_BASH_DIR}/lib_console.sh"COLOR_RESET: Reset the color.COLOR_BLACK: Black color.COLOR_RED: Red color.COLOR_GREEN: Green color.COLOR_YELLOW: Yellow color.COLOR_BLUE: Blue color.COLOR_MAGENTA: Magenta color.COLOR_CYAN: Cyan color.COLOR_WHITE: White color.COLOR_GRAY: Gray color.COLOR_LIGHT_RED: Light red color.COLOR_LIGHT_GREEN: Light green color.COLOR_LIGHT_YELLOW: Light yellow color.COLOR_LIGHT_BLUE: Light blue color.COLOR_LIGHT_MAGENTA: Light magenta color.COLOR_LIGHT_CYAN: Light cyan color.COLOR_LIGHT_WHITE: Light white color.
COLOR_BG_BLACK: Black background color.COLOR_BG_RED: Red background color.COLOR_BG_GREEN: Green background color.COLOR_BG_YELLOW: Yellow background color.COLOR_BG_BLUE: Blue background color.COLOR_BG_MAGENTA: Magenta background color.COLOR_BG_CYAN: Cyan background color.COLOR_BG_WHITE: White background color.
All logging functions to output information to STDERR. STDERR is preferred, as it is not affected by the output redirection of the script, thus, the desired standard output can be redirected to a file or another command.
Output debug message.
The function is used to output debug information. It is only printed
if the DEBUG variable is set to a value greater than 0 (zero).
If the standard output supports color, the debug information is printed in gray color. Otherwise, the debug information is printed without color.
Usage:
log_debug "Only show if DEBUG=1 (or more)"
grep "pattern" file.txt | log_debugOutput information message.
The function is used to output information messages. No extra color is used for the information message.
Usage:
log_info "An informational message."
grep "pattern" file.txt | log_infoOutput warning message.
The function is used to output warning messages. The warning message is printed in yellow color.
Usage:
log_warn "A warning notice."
grep "pattern" file.txt | log_warnOutput error message.
The function is used to output error messages. The error message is printed in red color.
Usage:
log_error "An error."
grep "pattern" file.txt | log_errorOutput a fatal error message.
The function is used to output error messages. The error message is printed with dark red background and bright yellow color.
Usage:
log_fatal "A fatal error."
grep "pattern" file.txt | log_fatalAlternative to cat that also processes colored input.
Usage:
ccat <<EOF
${COLOR_RED}This is red text.${COLOR_RESET}
${COLOR_YELLOW}This is yellow text.${COLOR_RESET}
EOF