Several ways the shell script executes

Source: Internet
Author: User

There are several ways to execute the shell script

1, relative path mode, you need to first CD to the script path

[[email protected] tmp]# Cd/tmp[[email protected] tmp]#./ceshi.sh Script Execution succeeded

2. Absolute path mode

[[email protected] tmp]#/tmp/ceshi.sh script executed successfully
3. Bash Command call

[[email protected]/]# bash/tmp/ceshi.sh script executed successfully

4,. (space) A relative or absolute way

[Email protected]/]#. /tmp/ceshi.sh Script Execution succeeded

The difference in several ways

There is no difference between the first and the second, both of which require a script to be given in advance to execute permissions.

The third is to handle the script as a bash call, so the script does not need to have execute permission to execute.

The first three methods are to open a child shell in the current shell to execute the script content, when the script content is finished, the child shell is closed, back to the parent shell.

The fourth is to make the script content execute in the current shell, rather than opening the shell alone.

The difference between the open shell and the non-open shell is that the inheritance of environment variables, such as the current variable set in a child shell, is not handled by a special channel, and the parent shell is not visible.

When executed in the current shell, all environment variables that are set are directly active.

Validation

[Email protected]/]# cat/tmp/ceshi.sh Top

1. Pstree display in the first three modes of execution

     ├─sshd─┬─sshd───bash───bash───top     │      └─sshd───bash───pstree
2. Pstree display under the fourth mode of execution

     ├─sshd─┬─sshd───bash───top     │      └─sshd───bash───pstree

3. Verify the inheritance relationship and visible relationship of environment variable setting

Build two scripts, father.sh and subshell.sh. where father.sh calls subshell.sh

Execution results are

[[email protected]/]#/tmp/father.sh invoke script output as child shell V_ceshi value Father Execute script output V_ceshi value to son in the current shell





Several ways the shell script executes

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.