0% found this document useful (0 votes)
16 views2 pages

UNIX Shell Scripts: Norman Matloff July 15, 2002

Shell scripts allow storing and executing Unix commands in files. They can be run with different shells like csh, sh, bash, and ksh. Shell scripts contain variables and flow control statements and are invoked either through direct interpretation by running the shell command on the file, or indirect interpretation by starting the file with a shebang line pointing to the shell interpreter.

Uploaded by

arunabhatla
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
16 views2 pages

UNIX Shell Scripts: Norman Matloff July 15, 2002

Shell scripts allow storing and executing Unix commands in files. They can be run with different shells like csh, sh, bash, and ksh. Shell scripts contain variables and flow control statements and are invoked either through direct interpretation by running the shell command on the file, or indirect interpretation by starting the file with a shebang line pointing to the shell interpreter.

Uploaded by

arunabhatla
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 2

UNIX Shell Scripts

Norman Matloff July 15, 2002

1 Introduction
In previous discussions we have talked about many of the facilities of the C shell, such as command aliasing, job control, etc. In addition, any collection of csh commands may be stored in a file, and csh can be invoked to execute the commands in that file. Such a file is known as a shell script file. The language used in that file is called shell script language. Like other programming languages it has variables and flow control statements (e.g. if-then-else, while, for, goto). In Unix there are several shells that can be used, the C shell ( csh and its extension, the T C shell tcsh), the Bourne Shell (sh and its extensions the Bourne Again Shell bash and the highly programmable Korn shell ksh ) being the more commonly used. Note that you can run any shell simply by typing its name. For example, if I am now running csh and wish to switch to ksh, I simply type ksh, and a Korn shell will start up for me. All my commands from that point on will be read and processed by the Korn shell (though when I eventually want to log off, exiting the Korn shell will still leave me in the C shell, so I will have to exit from it too).

2 Invoking Shell Scripts


There are two ways to invoke a shell script file.

2.1 Direct Interpretation


In direct interpretation, the command
csh filename [arg ...]

invokes the program csh to interpret the script contained in the file `filename'.

2.2 Indirect Interpretation


In indirect interpretation, we must insert as the first line of the file

#! /bin/csh

or
#! /bin/csh -f

You might also like