LNCD

Table of Contents

  • LNCD Home
  • Administration
  • Notebooks
  • Journal Club Presentations
  • Publications
  • Current Projects
  • Completed Projects
  • Current Grants
  • Datasets by Project
  • Brain ROIs and Measures
  • ️Tools And Methods
  • Big Data
  • RA Homepage
  • Undergrad Resources
  • Recent Changes
  • Maintenance
  • Site Map
  • Random Page
LNCD
Admin » Shell

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tools:shell [2023/09/19 10:09] – removed - external edit (Unknown date) 127.0.0.1tools:shell [2026/07/01 12:16] (current) – [Tutorials] will
Line 1: Line 1:
 +====== 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://seankross.com/the-unix-workbench/command-line-basics.html
 +  * 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/educational/unix_tutorial/index.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
 +<code=bash>
 +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
 +</code>
 +
 +===== 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
 +<code=bash>
 +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 # **
 +
 +</code>