Skip to content

Instantly share code, notes, and snippets.

@brianoflan
Last active December 16, 2016 17:46
Show Gist options
  • Save brianoflan/5009ca6173cb106b3393412265a9f1a6 to your computer and use it in GitHub Desktop.
Save brianoflan/5009ca6173cb106b3393412265a9f1a6 to your computer and use it in GitHub Desktop.
Handy ways to avoid set -e -x (execute, vexecute, die, log, elog, stderr)
#!/bin/bash
set -u ;
log=$(basename "$0" | sed -e 's/[.][^.]*$//') ;
elog="$log.stderr.log" ;
log="$log.stdout.log" ;
die() { echo $1 ; exit 1 ;
}
cd $(dirname $0) || die "ERROR: Failed to cd $(dirname $0): $? ." ;
thisD=$(pwd) ;
elog="$thisD/$elog" ;
log="$thisD/$log" ;
_ex() {
"$@" || die "ERROR: execute: $@: $?" ;
}
_vex() {
echo "$@" ;
"$@" || die "ERROR: vexecute: $@: $?" ;
echo ;
}
execute() { ( _ex "$@" 2>&1 ) >> $elog
}
vexecute() { ( _vex "$@" 2>&1 ) >> $elog
}
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment