DistributedNetworks DistributedNetworks

Unix Concepts   «Prev 

Storing your C Shell Settings - Shell Scripts

A shell script is a sequence of commands stored in a file. When you type the file name at the command line, you run the script as if it’s a new UNIX command.
Shell scripts are similar to batch files on Windows or DOS machines. The simplest scripts contain everyday UNIX commands, but scripts also understand their own programming language syntax. This syntax allows the use of variables, conditional execution (if-then logic), and repeated processing (looping).
As a simple example, suppose you’ve created a file named myscript that looks like this:

% cat myscript 
ls –F

Unix OS Design
For this file to work as a script, it must be executable. That means the author must have execute permission, so you change the access mode as follows:
% chmod u+x myscript

Now you can run the commands in the script by entering myscript at the command line:
% myscript
Sometimes when you run a shell script, you encounter a “Command not found” error. That’s because UNIX searches a particular set of directories when locating a command. The “Command not found” message means that the shell script is not in any of the places UNIX is searching. In the C shell, the path variable determines which directories will be searched.
Configuration files, such as .cshrc, are a special type of shell script. A configuration file is executed automatically, so you do not need execute permission on it.