Linux-------The creation of Shell programs and special characters

Source: Internet
Author: User

first, how to execute the shell script

Shell scripts are text files, so you can create and edit scripts with any text file editor (such as Vi,emacs, etc.). The name of the shell script file does not have a qualified suffix name, usually without a suffix name or with a ". Sh" suffix.

Shell scripts are executed in the following 3 ways:

(1) Execute the script as an executable file:

Script files generated with a text editor do not have x permissions by default, and they are not directly executed. Given R and X permissions, the script can be read and executed like a normal shell command. If the script is no longer stored in the default directory of the command, you need to execute the path name of the specified script. In the example above, the script hello is placed in the current directory, if the current directory is not the system default path will be used./sayhello to run, or directly execute SayHello can.


(2) Start a shell subprocess to execute the script file:

$bash SayHello

(3) Let the current shell process execute the script file:

Note that there are spaces behind!

“.” is the shell internal Command, SayHello is its argument. “.” The function of the command is to read the file specified by the parameter and execute its contents. This is done in a similar way to the second, except that this is done by the current shell process to execute the script file.


II. Input/Output redirection

(1) Additional redirects

">>" is a standard output additional redirect that redirects a standard output stdout or a standard error output stderr to a file in an append manner. 1>> or >> indicates that the stdout additional redirection,2>> represents stderr additional redirection.


Note: When the appended string has a space, use ""

(2) Use of Here documents

"<<" is a special standard input redirection mechanism called "here Document". The presentation format for the here document is:

<< end Tag String

Its purpose is to instruct the shell to pass the input line following this command line as the standard input to the command until the end tag string is encountered.




Linux-------The creation of Shell programs and special characters

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.