- yell: print the script name and all arguments to stderr:
$0
is the path to the script$*
are all arguments.>&2
means > redirect stdout to & pipe2
. pipe1
would bestdout
itself.
- die does the same as
yell
, but exits with a non-0 exit status, which means "fail". - try uses the
||
(booleanOR
), which only evaluates the right side if the left one didn’t fail.$@
is all arguments again, but different.
Last active
June 3, 2024 01:02
-
-
Save Gabelbombe/47d3102dc722a111c2505adf98504ae9 to your computer and use it in GitHub Desktop.
Yell Die Try functions for bash...
This file contains 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
#!/usr/bin/env bash -xe | |
function yell () | |
{ | |
echo "$0: $*" >&2 | |
} | |
function die () | |
{ | |
yell "$*"; exit 111 | |
} | |
function try () | |
{ | |
"$@" || die "cannot $*" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment