Using shell SCRIPTS
There are two main shell programming languages on the Athena system: "C-shell"
('csh') and "Bourne shell" ('sh'). Programs written in either of these
languages are called "shell scripts," and are stored in normal text files.
The default shell on Athena is actually the "T-shell" ('tcsh'), which is a
variation of the C-shell. Shell scripts for both 'csh' and 'tcsh' are
identical.
Both types of shell scripts contain commands that you would be able to give at
the prompt level.
For example, you could type:
echo "Hello world"
as a normal command, and you would see the response:
Hello world
You can put this command into a C-shell script to do the same thing:
#!/bin/csh -f
echo "hello world"
A C-shell script should always have '#!/bin/csh -f' as the very first line
in the file. This tells the command interpreter to use the C-shell rather
than the Bourne shell to execute the shell script. The '-f' option tells
it to not read your .cshrc file for a faster startup.
Shell languages provide many of the constructs used in C, using a very similar
syntax. If you know how to use C, you may want to write programs in C rather
than in a shell language because shell scripts take longer to start up and
execute.
To execute ("run") a shell script, it must be both readable and executable.
To do so, type the following command at your athena% prompt:
chmod 700 filename
Then just type the name of the shell script file, and it will be executed.
Unfortunately, the details of shell programming cannot be easily explained
briefly. To learn more about shell programming, you can read the manual pages
for 'csh' and 'sh' by using the 'man' command:
man csh
or
man sh
There are also a number of books on shell programming, which you can buy at
computer stores or at the Kendall Coop. Make sure that the book you purchase
is appropriate to the shell you want to use; most books only cover one of
them.
|