Skip to content

Common bash script library, with better error handling, status reporting and logging

License

Notifications You must be signed in to change notification settings

ssinha-ionos/bash_cmd_lib

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

bash_cmd_lib (WIP)

Common bash script library, with better error handling, status reporting and logging

Why you need this

  • Automatic error handling
  • Composable logging
  • Auto resource cleanup
  • Make errexit really work

Bash Pitfalls

Example

#!/bin/bash
. cmd_lib.sh

error_command() {
    do_something_failed
}

function bad_greeting() {
    local name="$1"

    info "Running error_command ..."
    error_command
    output "hello, ${name}!"
}

function good_greeting() {
    local name="$1"

    info "Running good_command ..."
    output "hello, ${name}!"
}

main() {
    local bad_ans
    bad_ans=$(_call bad_greeting "rust-shell-script")
    info "${bad_ans}"
    local good_ans
    good_ans=$(_call good_greeting "rust-shell-script")
    info "${good_ans}"
    return 0
}

main "$@"

ouput:

Running error_command ...
/bin/bash: line 219: do_something_failed: command not found
FATAL: Running command (bad_ans=$(_call bad_greeting "rust-shell-script")) near script hello.sh:main():1 failed (ret=127)

Related

See rust-shell-script

About

Common bash script library, with better error handling, status reporting and logging

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 100.0%