Linux ------- create Shell program and special characters, linux ------- shell

Source: Internet
Author: User

Linux ------- create Shell program and special characters, linux ------- shell
I. How to execute Shell scripts

Shell scripts are text files, so you can use any text file editor (such as vi and emacs) to create and edit scripts. The name of the Shell script file is not limited to the suffix name, usually without the suffix name or ". sh" suffix name.

Shell scripts can be executed in the following three ways:

(1) execute the script as an executable file:

By default, the script file generated in the text editor does not have the x permission, so it cannot be executed directly. After the r and x permissions are granted, the script can be read and executed as a Shell command. If the script is no longer stored in the default directory of the command, you must specify the script path name during execution. In the preceding example, the script hello is placed in the current directory. If the current directory is not the default path of the system, run it with./sayhello. Otherwise, run sayhello directly.


(2) Start a Shell sub-process to execute the script file:

$ Bash sayhello

(3) Let the Current Shell Process execute the script file:

Note: there is a space behind it!

"." Is an internal Shell command, and sayhello is its parameter. The "." command is used to read the file specified by the parameter and execute its content. This method is similar to the second method. The difference is that the current Shell process executes the script file.


Ii. Input/Output redirection

(1) additional redirection

">" Is an additional redirection character for the standard output. It redirects stdout or stderr to a file in the append mode. 1> or> indicates stdout additional redirection, 2> indicates stderr additional redirection.


Note: When the appended string contains spaces, use ""

(2) Use of the here document

"<" Is a special standard input redirection mechanism called "here document )". The format of the here document is:

<End tag string

It instructs Shell to pass the input line following this command line as the standard input of the command to the command until the end mark string is encountered.




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.