Point and source commands in LinuxShell scripts

Source: Internet
Author: User
In the LinuxShell script, the dot and source commands are used to determine whether a Linux file can run directly based on whether it has execution attributes. Just like exe in Windows. If you want to execute a file, you can first modify its permissions to executable (must be the owner or ro... in the Linux Shell script, the dot and source commands are used to determine whether a file in Linux can run directly based on whether it has execution attributes. Just like exe in Windows. If you want to execute a file, you can first modify its permissions to executable (only the owner or root can be modified ). Then run the script or./script name using sh. But sometimes we do not want to modify the file permission, and we may not have that permission, so we can use. (dot) + file name to temporarily execute a script without modifying the permission. There are a lot of scripts in the Linux system, and you will see a lot of built-in commands for executing bash Shell using the source Command (from the C shell. The Dot Command is another name of source (from the Bourne Shell. Similarly, the variables configured in the current script are used as the script environment. the source (or point) command is usually used to re-execute the modified initialization documents, such as. bash_profile and. profile. For example, if you modify the EDITER and TERM variables in. bash_profile after logon, you can run the source command again in. bash_profile without logging out and logging on again. The source command is used to execute a script. how is the difference between source a. sh and direct execution of./a. sh? For example, if you use export $ KKK = 111 in a script. /. sh: run the script. after the script is executed, run echo $ KKK and find that there is no value. if you use source to execute the script and then echo it, you will find that KKK = 111. Because of the call. /. sh to execute the shell is run in a sub-shell, so after the execution, the result is not reflected in the parent shell, but the source is different, it is executed in this shell, so we can see the results. Classic problem: shell script (test. sh) is as follows :#! /Bin/shecho "export monitor = 1"> after/etc/profilesource/etc/profile is called (. /test. sh), run echo $ monitor, and run echo $ monitor again after no manual source/etc/profile value is output, the source/etc/profile in the visible script has output the expected values (the reference itself is incorrect). how can this problem be solved? A: When you run test. sh, use source test. sh instead of./test. sh.
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.