If you only look at the previous theoretical section, although there are some examples, but the system is not enough, here we will show you the Linuxshell script programming, to help you learn and improve the foundation of Linuxshell. Linux shell script basics if you only look at the previous theoretical section, although there are some examples, but it is not systematic enough, here we will show you a specific example of Linux shell script programming, to help you learn and improve the basics of Linux shell.
Part 1 instances
Now let's discuss the general steps for writing a script. Any excellent script should have help and input parameters. And write a pseudo script (framework. sh) that contains the framework structure required by most scripts, which is a very good idea. At this time, when writing a new script, we only need to execute the copy command:
cp framework.sh myscript
Then insert your own function.
Let's look at another example:
Binary to decimal conversion
The script b2d converts the binary number (such as 1101) to the corresponding decimal number. This is also an example of a mathematical operation using the expr command:
#! /Bin/sh # vim: set sw = 4 ts = 4 et: help () {cat
The script uses decimal and binary weights (, 16,...). For example, binary "10" can be converted to decimal:
0 * 1 + 1 * 2 = 2
To obtain a single binary number, we use the lastchar function. This function uses wc-c to calculate the number of characters, and then uses the cut command to retrieve the last character. The Chop function removes the last character.
This Linux shell script instance helps us complete the conversion. next time we will give an example of a file loop program.
The above is a detailed introduction to basic learning of Linux shell scripts (7). For more information, see PHP Chinese network (www.php1.cn )!