Shell Comparison Reference Page

 


Variables
Feature
C
Bourne
Korn
Assigning Regular Variables
set x = 1
x=1
x=1
Accessing Regular Variables
echo $x
echo $x
echo $x
Assigning Arrays
set y=(1 2)
N/A
y[0]=1; y[1]=2
Accessing Array Elements
echo $y[1] $y[2]
N/A
echo $y
echo ${y[1]}
Accessing Entire Array
echo $y
echo $y[*]
N/A
echo ${y[*]}
Exporting Variables 
(Make Global)
use the setenv command
export var
export var
Command Line Arguments
$argv, $#argv, $argv[1]
   
Positional Parameters
$*, $1, ...
$*, $#, $1, ...
$*, $#, $1, ...
Setting Positional Parameters
   
set a b c

 
 
Metacharacters
Feature
C
Bourne
Korn
Single Character Wildcard
?
?
?
Any number of Characters
*
*
*
Set of Single Characters
[abc]
[abc]
[abc]
Range of Single Characters
[a-c]
[a-c]
[a-c]
Inverse Range of Single Characters
N/A
[!a-c]
[!a-c]

 
 
 
I/O Redirection and Piping
Feature
C
Bourne
Korn
Output to File
> filename
> filename
1> filename
> filename
1> filename
Input from File
< filename
< filename
0< filename
< filename
0< filename
Errors to File
N/A
2> filename
2> filename
Output & Errors to File
>& filename
N/A
N/A
Output to Next Command
 | cmd
 | cmd
 | cmd
Output & Errors to Next Command
 |&
N/A
N/A

 
Reading From the Keyboard
Feature
C
Bourne
Korn
Read keyboard input and store into one 
or more variables
set var = $<
read name1 ...
read name1 ...

 
Printing to the Screen
Feature
C
Bourne
Korn
Display text and variable values to the screen
echo (built-in command)
echo (utility)
print (built-in command)
echo (utility)

 
 
Math and Calculations
Feature
C
Bourne
Korn
Perform a Calculation
@ var = (a + b)
var=`expr a + b`
let var=a+b
Test a Relational Condition
@ var = (a < b)
var='expr a < b'
let var=a < b

 
Quoting Characters
Feature
C
Bourne
Korn
Single Quotes
'  '
'  '
'  '
Double Quotes
"  "
"  " 
"  "
Backslash
 \
 \
 \
(There is no significant difference between the shells for quoting.)



 

Aliases
Feature
C
Bourne
Korn
Create a new alias
alias name value
N/A
alias name=val
Display current list of aliases
alias
N/A
alias
Remove an alias from the list
unalias name
N/A
unalias name

 
 
 
History
Feature
C
Bourne
Korn
Turn history feature on
set history = num
N/A
automatic
Display list of remembered commands
history
N/A
history or fc
Display a partial listing
history n
N/A
history n m
history -n
Reexecute a command
!string
!number
!!
N/A
r string
r number
r

 
 
Command Substitution
Feature
C
Bourne
Korn
Execute Command and Replace syntax 
with the command's output
'command'
'command'
'command'
$(command)

 
 
Tilde Expansion
Feature
C
Bourne
Korn
Use the tilde (~) to represent the 
home directory of a user
~
~loginid
N/A
~
~loginid
Use the tilde to represent current 
and previous directories
   
~+
~-
-

 
Environment Files
Feature
C
Bourne
Korn
Read only on user 
logged in
.login
.profile
.profile
Read at each invokation 
of the shell
.cshrc
 
any file specified in .profile with:

ENV=.file


 
 
Built-In Editors
Feature
C
Bourne
Korn
Specify which editor 
to be used
N/A
N/A
set -o vi
set -o emacs

EDITOR=/usr/ucb/vi
EDITOR=/usr/ucb/vi


 
Functions
Feature
C
Bourne
Korn
Create a Function
N/A
func() {commands}
func() {commands}
function func {commands}
Use a Function
N/A
use func as a command
use func as a command

 
 
 
Typeset Command
Feature
C
Bourne
Korn
 
N/A
N/A
sets variable attributes

 
Programming Statements
Feature
C
Bourne
Korn
if Conditional
if (cond) then
   commands
else if (cond)
   commands
else
   commands
endif
if command
   commands
elif command
   commands
else
   commands
fi
same as the Bourne Shell
switch and case pattern
switch (thing)
   case pattern:
      commands
   default:
      commands
endsw
case thing in
   pattern)
      commands;;
   *)
      commands;;
esac
same as the Bourne Shell
while loops
while (cond)
   commands
end
while command
do
   commands
done
same as the Bourne Shell
for/foreach Loops
foreach var (list)
   commands
end
for var in list
do
   commands
done
same as the Bourne shell

Marty Froomin  7/9/03