No more spending time searching the special ways of bash for basic operations like “how to replace a string in bash”, then compare, choose, and test among many potential solutions.
Bash-base does this for you, you can just call the function here which is well tested and stable, and only focus you on the high level logic. Writing your script with less time, but more readability.
Available on GitHub, NPM and Docker Hub.
The reusable functions in src/ can be sourced by both Bash and zsh.
This matters on macOS, where zsh is the default interactive shell: source
bash-base is interpreted by the current shell, so the library itself must not
rely on hidden Bash-only syntax.
Existing Bash scripts and the Bash ShellSpec regression suite remain supported. A separate dual-shell compatibility gate runs the same core behavior under Bash and zsh.
See Bash and zsh compatibility for the exact contract, array portability boundary and test model.
Creat a sample script example_docker.sh with the following content:
#!/usr/bin/env bash
source <(docker run renaultdigital/bash-base)
SHORT_DESC='an example shell script to show how to use bash-base '
args_parse $# "$@" firstName sex
args_valid_or_read firstName '^[A-Za-z ]{2,}$' "Your first name (only letters)"
args_valid_or_select_pipe sex 'Mr.|Mrs' "Your sex"
confirm_to_continue firstName sex
print_success "Hello $sex $(string_upper_first "$firstName"), nice to meet you."
Assign the execute right to it:
chmod +x example_docker.sh
Run it:

# One line to import & download if not yet:
source <(docker run --rm renaultdigital/bash-base)
# Install the latest
npm i -g @renault-digital/bash-base
# Install from master branch
basher install renault-digital/bash-base
# Install the latest
curl -fsSL https://git.io/bashbase-i | bash
# Import latest version:
source <(curl -fsSL https://git.io/bashbase)
See GitHub releases or NPM tarball URLs
The possible values are:
print_error/print_headerprint_warn/print_args/print_success and those by level ERRORprint_info and those by level ERROR, WARNprint_debug and those by level ERROR, WARN, INFOLOG_LEVEL=${LOG_LEVEL:-$LOG_LEVEL_INFO}
The default value $LOG_LEVEL_INFO will be used if no config existed. you can override this default value in shell script, OS environment or ci/cd pipeline variables:
export LOG_LEVEL=$LOG_LEVEL_DEBUG
or
export LOG_LEVEL=1
SHORT_DESC='a bash script using bash-base'
redefine it to show your script short description in the ‘NAME’ field of generated response for **-h** argument.
USAGE=''
redefine it in your script only if the generated response for **-h** argument is not good for you.
See reference
See example folder, including the use case of **[Makefile](/bash-base/example/Makefile)**
See spec folder. Run npm test to execute the Bash/zsh compatibility gate followed by the existing Bash ShellSpec regression suite.
See change log
MIT.