The Linux Source command resolves the alias not found Issue__linux

Source: Internet
Author: User

Sometimes in our current shell, there is an alias command available, but when we sh script.sh or./script.sh, we find the error alias command not found problem.


What the hell is going on here? Because when you execute a new script with the current shell, the alias of the current shell is not automatically copied to the new shell that executes the script.sh script, so there is no such alias command.


One solution is to use the source command:

SOURCE script.sh

Causes the current shell to read into a file with a path of script.sh and executes all the statements in the file in turn.


So what's the difference between source and SH to execute a script?

The SH script.sh will re-establish a child shell, execute the script inside the child shell, the child shell inherits the environment variable of the parent shell, but the child shell is new and the changed variable will not be brought back to the parent shell unless using export.

Source script.sh is simply reading the script inside the statement in order to execute in the current shell, without creating a new child shell. Then all the new, variable-changing statements in the script will be saved in the current shell.


So what's the difference between SH script.sh and./script.sh?

The same is that they all create a new child shell to execute the script, and the difference is./script.sh requires script.sh to have execute permissions.


An example of a simple alias is:

Alias Ll=ls-l

Original: http://blog.csdn.net/hongchangfirst/article/details/78912188

Author: Hongchangfirst

Hongchangfirst's homepage: http://blog.csdn.net/hongchangfirst

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.