Last active
December 16, 2016 17:46
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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