Execute shell script and Subshell.

Source: Internet
Author: User

Two methods
    • Start a new shell and execute the shell scripts.
    • Shell scripts at the moment.

The scripts that brings up another shell will be added to the front of the scripts file.

      #! /bin/sh

The first approach is to point out the shell scripts program before the shell script file (that is, our shell) and then open the file with the permission to execute it as usual, or call a shell to explain the text file test.sh.

      $ test.sh      $/bin/sh test.sh      $ (. test.sh;)      $ exec test.sh

The second method is to use the command "." or source to execute.

      $ . test.sh      $ source test.sh      $ {test.sh;}      $ Eval '. Test.sh '

The difference is that some assumptions are only counted in this shell, and the other shell is another irrelevant world, that is, the setting of the variables in the script that is executed in the first way, does not affect the original shell variables. This is important. Ksh does not have the source command, so it is best not to use source. The brackets () denote the use of the current shell with another subshell large parenthesis. For example

      $ (var= ' TestVar ';)      $ echo $VAR      $ {var= ' TestVar ';}      $ echo $VAR      TestVar

Only the value in the Var inside {} is set. which is used. Be careful not to use it in script.

      $ . test.sh arg1 arg2

Because Arg1 Arg2 will continue to call this script's arg1 arg2 to use. The best way is to execute a script that is just a script library without parameters. In addition, if. Test.sh, test.sh leave, call. Test.sh's shell also leaves.

Execute shell script and Subshell.

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.