The shell provides a variety of mechanisms for the creation of individual working conditions. The shell ? – is more than a shell. The linux shell is also a powerful programming language. Method scripting shell ? – separate big topic, here we give only a few ways you can use to bring advanced capabilities to shell to facilitate the work in the system Linux.
When executing scripts different shells use different syntax. For example, the shell tcsh uses a syntax similar to the programming language C, while the shell bash uses the syntax of another type. In this section, these differences are not very significant, but still assumed that the shell scripts are executed bash.
The Linux shell scripts
Suppose that you often have to perform a sequence of linux shell commands, and you want to save time entering commands, grouping them into one team. For example, to concatenate files chapter1, chapter2 and chapter3 in a file named book, issue number of rows and print the file will be used in a sequence of three commands:
/ Home / larry# Cat chapter1 chapter2 chapter3 $> $ book
/ Home / larry# Wc-l book / home / larry # lp book
Rather than enter these three commands from the keyboard, you can combine them in Shell script. Script that will execute these three teams will look like this:
#! / Bin / sh
# Script to create and print books cat chapter1
chapter2 chapter3> book wc -l book lp book
The shell scripts are plain text files, they can create a text editor such as emacs or vi.
Consider this script. The first line #! / Bin / sh identifies this file as a script and tells the shell how to execute. This line tells the shell that this file should be transferred to the execution of the program / Bin / sh, Ie, the shell program itself. This line is important because in most systems Linux file / Bin / sh contains a shell-type bash. For example, bash and the string is forced to work in the shell executes the script using the syntax adopted in the shell bash (Rather than the syntax based on language C, for example). Even if, as start shell (Login shell) is used tcsh with this line, this script will execute the shell bash.
The second line is commentary (Comment). Comments start symbol # and continue until the end of the line. The shell ignores the comment. Usually the comments are used to indicate the purpose of the script and make it more understandable.
The remaining line of the script are the usual commands, such as if they were injected directly working with the shell. The shell reads each line of the script and executes it the same way as if the input line of the shell prompt.
Scripts are essential access rights. If you create a shell script, you need to ensure that you have the right to its execution. When you create text files, usually by default the right to execute the file is not given, and this right should be assigned to files explicitly. Installation and change the permissions discussed in detail above. For brevity, we indicate that in this case, if the script is written to a file makebook, you can use:
/ Home / larry# Chmod u + x makebook
This command will give you the right to execute script in a file makebook.
Now, to execute all the commands the script, only one team:
/ Home / larry# Makebook
Posted under Linux Tutorials
This post was written by Admin on October 8, 2010

















