====== Shell ====== eg. ''bash'' (''sh'' but "bourne" again), ''zsh'' (default for macOS), ''tcsh'' (NIH favorite) ===== Tutorials ===== * https://www.tutorialspoint.com/unix/index.htm starts super super basic but covers advance topics (via Orma) * https://missing.csail.mit.edu/2020/shell-tools/ via Warren * https://www.learnshell.org/ (via Amar) * [[https://afni.nimh.nih.gov/pub/dist/doc/htmldoc/background_install/unix_tutorial/basic/basic_03.scripts.html|AFNI's unix intro]] to scripting * [[https://andysbrainbook.readthedocs.io/en/latest/unix/Unix_Intro.html|Andy's brain blog book unix chapter]] includes videos * Pitt's [[https://crc.pitt.edu/|center for research computing]] suggests * https://cvw.cac.cornell.edu/Linux/default * https://software-carpentry.org/lessons/ ==== Readline Keyboard Shortcut reference ==== https://readline.kablamo.org/emacs.html ===== Utilities ===== fzf, fasd (z), readline editing options, alt+., ctrl+r, [[https://github.com/WillForan/fuzzy_arg|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 ===== Input Arguments ===== Both functions and scripts take "input arguments": what's provided to the right of the script or function. ''"$#"'' is number input args, ''"$*"'' is all as single string ''"$@"'' is each argument quoted ''$1'' .. ''$9'' are input arguments 1 to 9 (('$0' is the scripts name, ''$FUNCNAME'' is the current function)). ''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 # **