Source and the shell script file name to be executed. The differences between the shell script file name and the./shell script file name

Source: Internet
Author: User

The following content is based on the Linux bash Environment

There are many ways to run shell scripts in Unix. Suppose there is a script that can be run called test. sh. You can add the script file name, source test. sh (= .. /test. sh two .), you can also use. /path/test. sh mode. If the script is in the path, it can be run in bytes using the script name, such as test. sh.

The difference between them is:

Source test. Sh allows test. Sh to run in the current shell process without starting shell.

./Test. Sh (only one vertex) and test. Sh (test. Sh must be in the path) will start Shell Running.

In addition, when a shell script is placed in the path, especially when there is no sh suffix, if the system has alias, function and shell script with the same name, alias and function have a higher priority.

For example, the system has an alias: alias Ft = "Echo ft is an alias"

There is also a function also called ft () {echo ft is a function}

Then there is also an FT script file in the Path (for example, the current path directory is also set to path), with the content echo ft is in a script

If you run ft in shell, alias will be executed. If you remove alias and unalias ft, the function will be executed. If you want to execute the script ft, you can use./ft

When running the script is not the expected result, you can use the type script name to check whether there are alias and function with the same name. The type-all FT can be used to list all FT definitions.

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.