Linux --- shell --- 1 Command Execution

Source: Internet
Author: User
Tags shebang

Linux --- shell --- 1 Command Execution 1. how to execute commands in Shell 1> after you enter a command in the command line, shell will fork and exec the command, except for the built-in commands of Shell, executing a built-in command is equivalent to executing a Shell function and does not create a process. For example: cd/alias/umask/exit... 2> execute the script to write a simple script and save it as script. sh :----------------------------#! /Bin/sh cd .. ls ---------------------------- in the Shell script, use # to indicate the annotation, but if # is at the beginning of the first line and is #! (Shebang) is an exception. It indicates that the script is run with the interpreter/bin/sh specified later. Shell will fork a sub-process and call exec to execute the./script. sh program. The exec system call should replace the code segment of the sub-process with the code segment of the script. sh program and execute it from its _ start. However, script. sh is a text file with no code segment or _ start function. What should I do? In fact, exec has another mechanism. If you want to execute a text file and the first line of the text file is to use Shebang to create an interpreter, the current process is replaced with the interpreter code segment and executed from the interpreter's _ start. The text file is passed to the interpreter as a command line parameter. Therefore, executing the above script is equivalent to executing the program:, $/bin/sh./script. sh

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.