jmcantrell/bashful

Wrapper for RC != 0

Closed this issue · 2 comments

Sometimes it would be very handy to have a function like this:

check_rc()
{
  if [[ $? -gt 0 ]]; then
    if [[ ${1} != "" ]]; then
      echo -e "${@}"
    fi
    exit 1
  fi
}

I've used it a couple of times now in my own coding, allowing critical actions to abort scripts very handy.

startup_server 2> error.log
check_rc "Error: Could not start server, please check error.log!"

That's a great idea!

Closing for now. Way out of date and the pull request needs lots of work.