Shell Script notes (i) some bits and pieces of basic knowledge

Source: Internet
Author: User

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

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.