All tricks in this blog are only for educational purpose. Learn these tricks only for your knowledge. Please donot try these to harm any one. We will not take any responsibility in any case. All softwares and tools on this site are here for private purposes only and If you want to use a software for business purpose, please purchase it. I do not host many of these tools. I Post links that I have found from numerous Search engines. I will not be responsible for any of harm you will do by using these tools.


Thursday, September 23, 2010

Unix Shell Scripts

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, go to). 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 shellksh ) 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 commandcsh 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/cshor#! /bin/csh -f(there are situations in which this is not necessary, but it won’t hurt to have it), and the file must be made executable using chmod (see previous discussion). Then it can be invoked in the same way as any other command, i.e., by typing the script file name on the command line.The -f option says that we want fast start up, which it will achieve by not reading or executing the commands in .cshrc Thus for example, we won’t have the ‘set’ values for shell variables or the aliases from that file,but if we don’t need them, this will be much faster (if we need a few of them, we can simply add them to the script file itself).

Download Unix Shell Scripts.


Post a Comment