Some bits and pieces of basics I. Understanding shell scripts
a) Related concepts
The shell is a command interpreter that executes the commands and programs that the user enters in order (the command that encounters the sub-script, which executes the sub-script first).
The Shell scripting language is a weakly typed language, and the advantage over other scripting languages is that it can handle the underlying business of a biased operating system.
To view the system default shell:
#方法一: Echo $SHELL # Method Two: grep root/etc/passwd
II) Development Specifications
1) The first line of the script specifies the interpreter
2) Beginning to add version, copyright and other information
3) Try not to use Chinese in the script
4) extension. sh
5) script should be placed under fixed path
III) Methods of implementation
1) Bash Script-name or sh script-name: This method is also a common method if the script does not have X permissions or if the script does not specify an interpreter at the beginning.
2) Path/script-name: Execute script Under current path, script must have x permission.
3) source Script-name or. Script-name: Run the script directly in the current shell (other way to open the new shell), so you can pass the variables or functions in the script to the current shell.
IV) Redirection and piping
1) Output redirection
Send the output of the command to a file (each time a new file is created):
ls -al > List.txt
If you don't want to create a new file every time, you can append:
Date >> list.txt
2) Input redirection
Send the contents of the file to the command as relevant parameters:
ls in. txt
Inline input redirection:
Without the data in the file, redirect the data in the tag to the command in the syntax format:
Command << markerdatamarker
3) Piping
Use the pipeline to enter the output of one command as input to another, in the syntax format:
Command1 | Command2
V) Other
Execute multiple commands:
Put on the same line separated by semicolons
ls Date W.H.O.
Command substitution:
Extracts the information from the command output and assigns it to the variable.
Method One:
d=$ (date)
Method Two:
D= 'date'
Shell Script notes (i) some bits and pieces of basic knowledge