Chapter II Fundamentals of Shell programming

Source: Internet
Author: User
Tags garbage collection

2.1.1 Parameters for shell scripts

Common parameters

(1) * A string to display the parameters passed to the script, and the location variable, this parameter can be more than 9

(2) @ start at parameter 1, show all parameters passed to the script, and the above * similar, the following will describe the difference

(3) # Number of parameters, not including parameter 0

(4) The current ID number of the script run

(5)! Last ID number running in the background

(6)? Displays the exit status of the last command, 0 means no error, and any other value indicates an error

(7)-Displays the current options used by the shell, same as the SET command function

Note: The difference between ①* and @ is that when you add a double quote, the * outputs all parameters as a string output, which is "$ $ $"

And @ is a single output of all the parameters, that is, "$" "$" "$"

②-minus sign, mainly used in the standard input and output, in the pipeline application, can save us the process of creating temporary files

2.1.2 MV Move or rename a file or directory

Common parameters

(1)-f//Warn if file space retention or fixed range size cannot be saved

(2)-I//do not prompt before overwriting existing files

2.1.3 Mkidr Create one or more new directories

Common parameters

(1)-m Specify folder permission size

2.2.1 I/O redirection

2.2.2 Cat connection or display files

Common parameters

(1)-N//Display line number

(2)-b//Show non-blank line number

(3)-S//There are two consecutive lines in the sky, then only a row of empty lines, other omitted

Note: ①tac displays files from the end to the beginning

② do not use redirection symbols > redirect output to the input file. Because the shell truncates the file before the cat command can read it.

2.2.3 | Pipeline

The data sharing of pipelines is implemented in the kernel through memory copy, therefore, when designing the pipeline, we should try to put the data quantity of Jiangsu into the pipeline front-end.

2.2.4 Head Displays the first few lines or the first few bytes of a file or multiple files

Main parameters

(1)-N//Specify the number of rows to display, default to 10

(2) can also be connected to multiple files behind

2.2.5 File Descriptor

This part is a bit difficult,,,,

After studying, I'll add it.

2.2.6 Special Files

(1)/dev/null is like a "black hole", garbage collection station, written in the file is unreadable, you can add unwanted junk files to the file.

(2)/dev/zero This is used to create a file of a specified length and is initialized to an empty file, which is generally used as a temporary interchange file.

(3)/dev/tty writes the contents of this file can be displayed on the screen, very often

printf "Enter new passwd:"//Prompt input

Stty-echo//Turn off the ability to automatically print input characters

Read Pass </dev/tty//reading password

printf "Enter Again"//read once, Confirm password

Read pass2</dev/tty//Remember to re-open the auto-print input character feature

Stty Echo

2.2.7 read reads a row from the standard input.

Main parameters:

(1)-a followed by a variable, which is considered to be a group, and then assigned a value, by default, the space is a separator.

(2)-D followed by a marker, in fact, only the first character after the useful, as the end of the flag, will be illustrated.

(3)-p followed by a prompt message, that is, before the input to print the message.

(4)-E can use command complement function when inputting.

(5)-n followed by a number that defines the length of the input text, which is useful.

(6)-R Shield, if there is no option, then as an escape character, there is a normal character.

(7)-s quiet mode, no longer displays on the screen when entering characters, such as entering a password when login.

(8)-T followed by the number of seconds, defining the wait time for the input character.

(9)-U followed by FD, read in from the file descriptor, the file descriptor can be exec new open.

2.3 All Documents

The type of file in common

(1)-Normal file

(2) d catalog file

(3) C-Character device files

(4) B Block equipment file

(5) s set of interface files

(6) L Symbolic Link file

(7) Piping files

  

  

Chapter II Fundamentals of Shell programming

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.