Skip to content

Latest commit

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date

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
}
functionbad_greeting() {
local name="$1"
info "Running error_command ..."
error_command
output "hello, ${name}!"
}
functiongood_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

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages