Small issues encountered when learning shell scripts

Source: Internet
Author: User


1. Add-x to execute the shell script, and list the process when executing the script! (For beginners like me) sh-x shell (. /shell can also execute shell scripts, but there is no-x parameter) 2. when the number of passed values is greater than the read-defined accept variable, extra values are given to the last variable !! 3. expr is used to calculate Integer Variables. If the calculation result is not all after the integer decimal point, it is omitted (the multiplication character must be an escape character '\'). 4. execute an output command (pgrep mysqld) in the shell script. How can I assign the output result to the variable as a value? Web = $ (/usr/bin/pgrep mysqld) # You can use the variable =$ (command) and variable = 'COMMAND 'to assign the result of command execution to the variable.
If [$ web =]
Then
/Etc/init. d/mysql start
Fi

5. You can use the whereis/which/type command to view the location of a command. 6. The application of the awk command: Segment extraction! (One row is used for segmentation) awk-F [separator] 'condition action'/object example: awk-F: '$3 = 0 {print $1}'/etc/passwd example: awk-F: '$1 = root {print $1}'/etc/passwd #-F: use: split the content of each row of passwd ($1 refers to the content of the first section $2 refers to the content of the second section $ n refers to the content of the n section) # The match command and the print action match $3 = 0 in single quotes. The third section equals 0. print {print $1}. print the first section ($3 = 0. Match the first line of the trip)

Related Article

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.