Always wondered what is the difference between these four shells? Here’s the answer.
As a command line beginner or new Linux/Unix user, you must have come across these common shell names, Standard shell (sh), Bourne Again SHell (bash), Korn shell (ksh) and the C shell (csh). And if you are among those wondering what makes them stand apart from each other, here’s a comparative chart for you to see.Please note how bash incorporates almost every concept from other shells, as there are no blanks in the column for bash. Moreover, this is just a comparative list that lays out the major differences between the standard shell (sh), Bourne Again SHell (bash), Korn shell (ksh) and the C shell (csh).
Meaning/Action | sh | ksh | csh | bash |
Default user prompt | $ | $ | % | $ |
Force redirection | >| | >! | >| | |
Redirect stdout and stderr to file | > file 2>&1 | > file 2>&1 | >& file | &> file or > file 2>&1 |
Expand elements in list | { } | { } | ||
Substitute output of enclosed command | `command` | $(command) | `command` | `command` or $(command) |
Home directory | $HOME | $HOME | $home | $HOME |
Home directory symbol | ~ | ~ | ~ | |
Access directory stack | ~+, ~- | Err:511 | ~+, ~-, dirs | |
Variable assignment | var=value | var=value | set var=value | VAR=value |
Set environment variable | export var | export var=val | setenv var val | export VAR=value |
More than 9 arguments can be referenced | ${nn} | ${nnnn} | ||
All arguments as separate words | “$@” | “$@” | “$@” | |
Number of arguments | $# | $# | $#argv | $# |
Exit status of the most recently executed command | $? | $? | $status | $? |
PID of most recently backgrounded process | $! | $! | $! | |
Current options | $- | $- | $- | |
Read commands in file | . file | . file | source file | source file or . file |
Name x stands for command y | alias x=y | alias x y | alias x=’y’ | |
Choose alternatives | case | case | switch or case | case |
End a loop statement | done | done | end | done |
End case or switch | esac | esac | endsw | esac |
Exit with a status | exit n | exit n | exit (expr) | exit n |
Loop through variables | for/do | for/do | foreach | for/do |
Ignore substitution characters for filename generation | noglob | set -f , set -o nullglob|dotglob|nocaseglob|noglob | ||
Display hashed commands (tracked aliases) | hash | alias -t | hashstat | hash |
Remember command locations | hash cmds | alias -t cmds | rehash | hash cmds |
Forget command locations | hash -r | unhash | hash -r | |
List previous commands | history | history | history | |
Redo previous command | r | !! | ArrowUp+Enter or !! | |
Redo last command that starts with “str” | r str | !str | !str | |
Replace “x” with “y” in most recent command starting with “cmd”, then execute. | r x=y cmd | !cmd:s/x/y/ | !cmd:s/x/y/ | |
Sample condition test | if [ $i -eq 5 ] | if ((i==5)) | if ($i==5) | if [ $i -eq 5 ] |
End if statement | fi | fi | endif | fi |
Set resource limits | ulimit | ulimit | limit | ulimit |
Print working directory | pwd | pwd | dirs | pwd |
Read from terminal | read | read | $< | read |
Ignore interrupts | trap 2 | trap 2 | onintr | trap 2 |
Remove aliases | unalias | unalias | unalias | |
Begin until loop | until | until | until | |
Begin while loop | while/do | while/do | while | while/do |