[The source command in the]shell is followed by a dot space and a description of the executable file

Source: Internet
Author: User

It's recorded in a shell script.
. ./file.sh and
/file.sh the difference, this article refers to the http://www.lslnet.com/linux/dosc1/39/linux-283534.htm (this blue forest thing should be derived from Chinaunix)


A little experiment.
Scenario One:
VI file1.sh
./file2.sh
Echo $NIVEK

VI file2.sh
Nivek=goupi
Export Nivek

chmod 755 file1.sh file2.sh

$./file1.sh
Without any output
$

Scenario Two:
VI 1file.sh
. ./2file.sh
Echo $NIVEK

VI 2file.sh
Nivek=goupi
Export Nivek

chmod 755 1file.sh 2file.sh

$./1file.sh
Goupi//2file.sh The value of the variable Nivek in the export
$

From this we can see the difference between them, namely
The./file.sh will reboot a new child shell to execute it, so if some of the variables defined in the file.sh (export) are only useful in the child shell, the return will be lost.

. ./file.sh does not start a new shell and executes in the current shell, so the variable defined in file.sh still works after it is returned.


Let's look at this simple example:
Cat 1.sh
#!/bin/bash
Sleep 1
Exit 1

Cat test1.sh
#!/bin/bash
./1.sh
echo "Can See Me"

Cat test2.sh
#!/bin/bash
. ./1.sh
echo "Can See Me"

Perform test1.sh separately, test2.sh from their differences can see a few different

Reference

Http://blog.chinaunix.net/uid-20652643-id-1906458.html

[The source command in the]shell is followed by a dot space and a description of the executable file

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.