Summary of LinuxShell script strategy: 1

Source: Internet
Author: User
Summary of LinuxShell script introduction: There are two common commands for printing on a terminal printing terminal: echo and print. first, I will introduce echo1.echoecho, which accepts three types of parameters. The example is as follows: [python] echo & quot; HelloWorld & quot; echo & amp; #39; HelloWorld... summary of Linux Shell script introduction: There are two common commands for printing on a terminal printing terminal: echo and print. first, I will introduce echo1.echoecho, which accepts three types of parameters. The example is as follows: [python] echo "Hello World" echo 'hello world' echo Hello World commands output the same results. However, each method has its corresponding "Side Effects", such as the following results: from the results, we can see that commands with double quotation marks as parameters do not recognize punctuation marks. at this time, if double quotation marks are still used, we can add escape characters and Use the-e parameter, for example, [python] echo-e "Hello World \! "2. the print command requires the printf function in Lenovo C language, because it uses the same method and function. let's look at an instance [python] #! /Bin/bash # Filename: printf. sh printf "%-5 s %-10 s %-4s \ n" No Name Mark printf "%-5 s %-10 s %-4.2f \ n" 1 Sarath 80.3456 printf "%-5 s %-10 s %-4.2f \ n" 2 James 90.9989 printf "%-5 s %-10 s %-4.2f \ n" 3 Jeff 77.564 run this instance, the following results show that the variables in the variable Shell have the following features: 1. variables are not declared. all variables are defined using var = value. note: spaces are not allowed on both sides of the equal sign. the value of any variable is a string. let's look at an example: [python] #! /Bin/bash # Filename: variables. sh fruit = apple count = 5 echo "We have $ count $ fruit (s)" output result: Appendix: We can obtain the length of the variable value through the corresponding method: [python] Length =$ {# var}For example, the field delimiter IFS (internal field separator) is an important concept in Shell scripts. It is useful when processing text data. The internal field delimiter is a delimiter used for a specific purpose. IFS is the environment variable that stores the delimiters. It is the default delimiter used by the current shell environment. Example: [python] #! /Bin/bash # passwd_line.sh # Description: Illustration of IFS line = "root: x: 0: 0: root:/bin/bash" oldIFS = $ IFS; IFS = ":" count = 0; for item in $ line; do [$ count-eq 0] & user = $ item; [$ count-eq 6] & shell = $ item; let count ++ done; IFS = $ oldIFS echo $ user \'s shell is $ shell; the running result is as follows:

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.