C.2. Differing features

The table below shows major differences between the standard shell (sh), 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. Since the Turbo C shell is a superset of csh, all csh commands will work in tcsh. For more details on these two popular shells, see man the man pages for these shells on your system.

Table C-2. Differing Shell Features

shkshcshMeaning/Action
$$%Prompt
  >!Force redirection
  >>!Force append
> file 2>&1> file 2>&1>& fileCombine stdout and stderr
  { } Expand elements in list
` `$( )` `Substitute output of enclosed command
$HOME$HOME$homeHome directory
 ~~Home directory symbol
var=valuevar=valueset var=valueVariable assignment
export varexport var=valsetenv var valSet environment variable
 ${nn} More than 9 args can be referenced
"$@""$@" All args as separate words
$#$#$#argvNumber of arguments
$?$?$statusExit status
$!$! Background exit status
$-$- Current options
. file. filesource fileRead commands in file
 alias x=yalias x yName x stands for y
casecaseswitch/caseChoose alternatives
 cd ~-popd/pushdSwitch directories
donedoneendEnd a loop statement
esacesacendswEnd case or switch
exit [n]exit [n]exit [(expr)]Exit with a status
for/dofor/doforeachLoop through variables
 print -rglobIgnore echo escapes
hashalias -thashstatDisplay hashed commands (tracked aliases)
hash cmdsalias -t cmdsrehashRemember command locations
hash -r unhashForget command locations
 historyhistoryList previous commands
 r!!Redo previous command
 r str!strRedo command that starts with str
 r x=y cmd!cmd:s/x/y/Edit command, then execute
if [ $i -eq 5 ]if ((i==5))if ($i==5)Sample if statement
fifiendifEnd if statement
ulimitulimitlimitSet resource limits
pwdpwddirsPrint working directory
readread$<Read from terminal
trap 2trap 2onintrIgnore interrupts
 unaliasunaliasRemove aliases
untiluntil Begin until loop
while/dowhile/dowhileBegin while loop

Bash specific features:

More information:

You should at least read one manual, being the manual of your shell. Print it out and take it home, study it whenever you have 5 minutes.