$FUNCNAME is the current functionThis is an old revision of the document!
Shell
eg. bash (sh but “bourne” again), zsh (default for macOS), tcsh (NIH favorite)
Utilities
fzf, fasd (z), readline editing options, alt+., ctrl+r, fuzzy ctrl+r, alt+n newfiles
Idioms
short if-statements. short form function definitions. regexp w/BASH_REMATCH
if [ -r file.txt ]; then rm file.txt fi # same as [ -r file.txt ] && rm file.txt # same as test -r file.txt && rm "$_" #### function abc { echo abc } # same as abc(){ echo abc; } ### foobar="a1 b2 c3" [[ $foobar =~ c.* ]] && echo $BASH_REMATCH # c3
Niche
“$#” is number input args, “$*” is all as single string “$@” is each argument quoted
$1 .. $9 are input arguments 1 to 9 1). printf like echo but first argument is how to format what follows
nargs() { echo "$#"; } arg_at() { nargs "$@"; } arg_star() { nargs "$*"; } arg_at a b c # 3 arg_star a b c # 1 second() { printf "*%s*\n" "$2"; } arg_at2() { second "$@"; } arg_star2(){ second "$*"; } arg_at2 a b c # *b* arg_star2 a b c # **
1)
'$0' is the scripts name,