A.2. Differing features

The table below shows major differences between the standard shell (sh), Bourne Again SHell (bash), Korn shell (ksh) and the C shell (csh).

NoteShell compatibility
 

Since the Bourne Again SHell is a superset of sh, all sh commands will also work in bash - but not vice versa. bash has many more features of its own, and, as the table below demonstrates, many features incorporated from other shells.

Since the Turbo C shell is a superset of csh, all csh commands will work in tcsh, but not the other way round.

Table A-2. Differing Shell Features

shbashkshcshMeaning/Action
$$$%Default user prompt
 >|>|>!Force redirection
> file 2>&1&> file or > file 2>&1> file 2>&1>& fileRedirect stdout and stderr to file
 { } { }Expand elements in list
`command``command` or $(command)$(command)`command`Substitute output of enclosed command
$HOME$HOME$HOME$homeHome directory
 ~~~Home directory symbol
 ~+, ~-, dirs~+, ~-=-, =NAccess directory stack
var=valueVAR=valuevar=valueset var=valueVariable assignment
export varexport VAR=valueexport var=valsetenv var valSet environment variable
 ${nnnn}${nn} More than 9 arguments can be referenced
"$@""$@""$@" All arguments as separate words
$#$#$#$#argvNumber of arguments
$?$?$?$statusExit status of the most recently executed command
$!$!$! PID of most recently backgrounded process
$-$-$- Current options
. filesource file or . file. filesource fileRead commands in file
 alias x='y'alias x=yalias x yName x stands for command y
casecasecaseswitch or caseChoose alternatives
donedonedoneendEnd a loop statement
esacesacesacendswEnd case or switch
exit nexit nexit nexit (expr)Exit with a status
for/dofor/dofor/doforeachLoop through variables
 set -f, set -o nullglob|dotglob|nocaseglob|noglob noglobIgnore substitution characters for filename generation
hashhashalias -thashstatDisplay hashed commands (tracked aliases)
hash cmdshash cmdsalias -t cmdsrehashRemember command locations
hash -rhash -r unhashForget command locations
 historyhistoryhistoryList previous commands
 ArrowUp+Enter or !!r!!Redo previous command
 !strr str!strRedo last command that starts with "str"
 !cmd:s/x/y/r x=y cmd!cmd:s/x/y/Replace "x" with "y" in most recent command starting with "cmd", then execute.
if [ $i -eq 5 ]if [ $i -eq 5 ]if ((i==5))if ($i==5)Sample condition test
fififiendifEnd if statement
ulimitulimitulimitlimitSet resource limits
pwdpwdpwddirsPrint working directory
readreadread$<Read from terminal
trap 2trap 2trap 2onintrIgnore interrupts
 unaliasunaliasunaliasRemove aliases
untiluntiluntil Begin until loop
while/dowhile/dowhile/dowhileBegin while loop

The Bourne Again SHell has many more features not listed here. This table is just to give you an idea of how this shell incorporates all useful ideas from other shells: there are no blanks in the column for bash. More information on features found only in Bash can be retrieved from the Bash info pages, in the "Bash Features" section.

More information:

You should at least read one manual, being the manual of your shell. The preferred choice would be info bash, bash being the GNU shell and easiest for beginners. Print it out and take it home, study it whenever you have 5 minutes.