The difference between Shell script and different running modes

Source: Internet
Author: User

There are three main ways of running shell scripts in Linux:

1. Direct command release: The shell.sh file must have readable and operational (RX) permissions, and then:

Absolute path: Use/home/dmtsai/shell.sh to release commands;

Relative path: If the working directory is/home/dmtsai/, use./shell.sh to run

variable "path" function: Place the shell.sh in the directory where path refers fixed , for example: ~/bin/

2. Run as a bash program: Run through "bash shell.sh" or "sh shell.sh"

3. Run with the source shell.sh command

The difference: The first and the second are all running in the subroutine bash (Figure 1), and the third is running in the main program bash (Figure 2). When running in the first two ways, all the variables or actions created in the script will end without going back to the main program, and the third will add the variables to the main program bash.


Figure 1, sh02.sh running in a sub-program



Figure 2, sh02.sh running in the parent program


The difference between Shell script and different running modes

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.