Advanced bash - http://www.deadman.org/bash.html

history - shows history
!!   - repeats last command
!xyz - run last command starting xyz
:p   - practice/print command: 
     - !xyz:p # shows what would run
     - follow by !! to actually execute
!N - execute command N (N is the number in the history)
^r - search through history
^u - delete from here to start of line
^w - delete word
^a - ^ (start of line)
^e - $ (end of line)

!$ - last argument of the previous string
   - ls wxyz abcdefghijkl
   - vi !$ # will edit abcdefghijkl
!* - all the arguments
   - ls wxyz abcdefghijkl
   - cat !* will cat wxyz abcdefghijkl
^X^Y - replace X with Y in previous command
       ls /etc/x11/xorg.conf # wrong
       ^x11^X11 # fixes

{a,b} - brace expansion
        cp file-{v1,v2} # cp file-v1 file-v2
        ls /usr/{,local/}{,s}bin/jojo # ls /usr/local/bin/jojo /usr/bin/jojo 
                                         /usr/local/sbin/jojo /usr/sbin/jojo

!-N - the Nth previous command
    cat doc
    cd def
!-2$ # $ means the final argument in the -2nd command
!-2* # * means all the arguments in the -2nd command
!-2  # execute the whole thing in the -2nd command
    
:h - remove a trailing filename component leaving only the head
:t - Remove all filename components leaving only the tail
:r - Remove a trailing suffix of the form .xxx, leaving only the basename
:e - Rmove all but the trailing suffix
:s - Subsitution (same a ^X^Y) (only replaces first instance)
:sg - global substitution (replace all instances)

  tar xf abc.tgz
  mkdir !$:r # creates abc directory

  Can chain

  tar xf abc.tar.gz
  mkdir $!:r:r # creates abc directory

In substitutions can use & as $1
!!:s/myfile/&.old/ is the same as !!:s/myfile/myfile.old/


function name { arg1 = "${1}"; echo "${2}"; cmd = "${0}"; 
                allargs = "${*}";
                numargs = "${#}";
              };