Bash Utils

bash_utils.bsh

A few utilities to help scripts in bash.

Prints the current call stack

Arguments:
  • $1 - Number of stack levels to skip (not including print_bash_stack itself. It will automatically add one to this number for itself). You typically set this to 1 in a function that gets called to print the stack. Default: 0

  • [$2] - Optional function to customize the printing of the stack. Variables you can expect to be set are (actual) stack_depth, stack_depth_pad, BASH_LINENO, lineno_pad, FUNCNAME, funcname_pad, and BASH_SOURCE

run_bash_with_rc_file

Depending on how bash is compiled (-DSYS_BASHRC), spawning bash with a custom RC file is not always straight forward. This function will normalize this behavior so that no matter what version/configuration of bash you are running, your RC files will be loaded before running the desired bash command.

Note

This is intended for interactive shells only. Any arguments added that make the shell non-interactive effective nullify the purpose of this function

Arguments:
  • $1 - A string containing the run commands (RC)

  • [$2...] - Args to be passed bash

Parameters:

[BASH_EXEC] - Set to “exec” to exec bash instead of calling bash