The difference between a Linux shell source and a.

Source: Internet
Author: User

First, use '. ' Perform1. Contents of the file:

a.sh

#!/bin/sha=2echo a= $a

b.sh

#!/bin/sh./a.shecho a.sh:a= $a

2. Add executable permissions
# chmod +x a.sh b.sh

3. Running
#./b.sh a=2a.sh:a=

It can be seen that a in b.sh does not get the A variable in a.sh, it just executes the a.sh once.

second, using Source to execute

1. Contents of the file:

a.sh

#!/bin/sha=2echo a= $a

b.sh

#!/bin/shsource./a.shecho a.sh:a= $a

2. Add executable permissions
# chmod +x a.sh b.sh

3. Running
#./b.sh a=2a.sh:a=2

A variable in a.sh is obtained in the visible b.sh

Iii. Conclusion

In fact, '. ' Just executes the shell script once, and source is adding code from the shell script to the current script, similar to the Include in C.

We'll use Bash-x to see the details.

1) '. ' The way

# sh-x b.sh +./a.sha=2+ echo a.sh:a=a.sh:a=

2) Source of the way

# sh-x b.sh + source./a.sh++ a=2++ echo a=2a=2+ Echo a.sh:a=2a.sh:a=2

Can see '. ' The way only executes the a.sh and outputs the results of a.sh a=2; The source method is to add the a.sh code to the b.sh and then execute.


The difference between a Linux shell source and a.

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.