Bash

The Startup files

 
Login shells:
         On login (subject to the -noprofile option):
               if /etc/profile exists, source it.

               if ~/.bash_profile exists, source it,
                 else if ~/.bash_login exists, source it,
                   else if ~/.profile exists, source it.

         On exit:
               if ~/.bash_logout exists, source it.

       Non-login interactive shells:
         On startup (subject to the -norc and -rcfile options):
               if ~/.bashrc exists, source it.

       Non-interactive shells:
         On startup:
               if the environment variable ENV is non-null, expand
               it and source the file it names, as if the command
                       if [ "$ENV" ]; then . $ENV; fi
               had been executed, but do not use PATH to search
               for the pathname.  When not started in Posix mode, bash
               looks for BASH_ENV before ENV. 

 Filename Expansion

* means at least one char
? means exactly one char
[2-7] means either 2 or 3 or 4 or 5 or 6 or 7
[^a] means any char except an 'a'
$a means the value of the variable a

Command History

!fred means run the last command that started with 'fred'
!-2 means run soemhting two commands ago
^clobber^gub^ means run the last command, but replace the string 'clobber' with 'gub' before you start it,

Redirection

>fred means put the stdout into the file 'fred'
<fred means put the stdin from the file 'fred'
2>fred means put stderr into fred (/dev/null works nicely here)
2>1 means make stderr become stdout

Special Variables

 
$$ The PID of the shell
$! The PID of the most recently executed background task
$?  The staus of the most recently executed foreground task
$0 The name of the shell script currently running
$PWD The present working dir
$UID The user ID of the person running the script
$EUID The effective UID of the person running the script
$RANDOM A random number
$SECONDS The number of seconds since the script started
$LINENO The current line number.  Useful for errors.
$IFS The Internal field seperator.  Normally a ' '
$PATH The path to search for commands.  Should '.' be in the path?
$HOME Your home directory.  Changeable!!
$CDPATH The path to search when you type 'cd'.
$PS1 Your normal prompt
$PS2 Your secondary prompt.  Nornally used when you have a running quote or a running do ... done loop
$TMOUT How long to wait for input before logging someone out.  Good for security.
$noclobber If this has a value, then you cannot with redirection clobber an existing file.  Can be unset with 'unset noclobber'

A few commands

 
let a=3+2/4 Math!!
read a b c  Read stdin.  The first word is $a, the second is $b, and anything else is $c.
pushd /tmp change the cwd to /tmp.  Store the pwd in a stack.
popd Go back to where the last pushd left from.
exec /usr/bin/vi Ends the script.  /usr/bin/vi is started,
shift $9 becomes $8, $8 becomes $7, $7 becomes $6, etc.
times view resource consumption

Ulimit

[randy@googee randy]$ ulimit -a
core file size (blocks)  1000000
data seg size (kbytes)   unlimited
file size (blocks)       unlimited
max memory size (kbytes) unlimited
stack size (kbytes)      8192
cpu time (seconds)       unlimited
max user processes       2048
pipe size (512 bytes)    8
open files               1024
virtual memory (kbytes)  2105343
 
-a report all limits
-c Max size of core files.  Set to zero to not get core files.
-d Processes data segment
-f Max size of a file created by shell redirection.
-m Max resident set size. 
-s Max stack size.  Stops runaway recursive calls.
-t Max CPU time in seconds
-u Max number of processes