Linux shell script basics (7)

Source: Internet
Author: User
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 )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.