next up previous contents
Next: Shell Programming Up: Shell Programming Previous: tcsh builtin commands, startup

Comparison of Shells

Before concluding our shell documentation, we feel useful to show the difference among shells with a simple application that creates and updates a database of the user's scripts storing informations like script name, script usage and script shell. The database follows Unix conventions for similar informations, like the password database where entries are made of alphanumeric strings terminated by eol and : is used as field separator.

The script is implemented using Bourne, C and Korn shells. The script is called db prefixed by a letter referencing the implementation shell, therefore the different versions are called bdb, cdb, kdb. The script exercises the following shell features:

Below are listed the sh, csh, ksh versions of the scripts.



{
bdb script
#!/bin/sh
#---------dbase to compare shells----------------
#
while echo "End or Command: "
read cmd
do
case $cmd in
'end') break #end proc
;;
*) echo "shell: "
read shc
echo "Usage: "
read usg
echo $cmd:$shc:$usg: >> cmd.dbs
;;
esac
done
#
#---------end script-------------



The script reads data from keyboard in variable cmd and tests for input termination. When end is typed the procedure ends and the database file is closed. For any other value of cmd, the script reads with inquiry two other values in shc and usg and appends the inquired data to file cmd.dbs using the echo command to collate fields and field separators and the redirection feature to write file.


{
cdb script
#!/bin/csh
#---------dbase to compare shells----------------
#
set loop = 0
while ($loop <= 0)
echo "End or Command: "
set cmd = $<
switch ($cmd)
case [eE][nN][dD]
set loop = 1
breaksw #end proc
default:
echo "shell: "
set shc = $<
echo "Usage: "
set usg = $<
echo $cmd":"$shc":"$usg":" >> cmd.dbs
endsw
end
#
#---------end script-------------



The C shell version of the procedure uses the loop variable to terminate the while loop. In bdb script the termination word was checked with lowercase letters, here the test is done on any combination of upper and lower case letters. Note the usage of the set command.



next up previous contents
Next: Shell Programming Up: Shell Programming Previous: tcsh builtin commands, startup
Marisa Luvisetto
2001-02-05