Differences between source exec (extracted from shell 13)

Source: Internet
Author: User

Exec also allows the script to be executed in the same process, but the original process is ended.

 

Script content:

Root @ James-desktop:/opt/Qt-everywhere/Marvell/APP/applications/factory-Roast # Cat 1.sh
#! /Bin/sh
A = B
Echo "PID for 1.sh: $"
Export
Echo "1.sh \ $ A is $"
Case $1 in
Exec)
Echo "using exec ..."
Exec./2.sh ;;
Source)
Echo "using source ..."
Source./2.sh ;;
*)
Echo "using fork ..."
./2.sh ;;
Esac

Echo "PID for 1.sh after run 2.sh:$ $"
Echo "1.sh \ $ A is $"

Root @ James-desktop:/opt/Qt-everywhere/Marvell/APP/applications/factory-Roast # Cat 2.sh
#! /Bin/sh
Echo "PID for 2.sh: $"

Echo "2.sh get \ $ A = $ A from 1.sh"
A = C
Export
Echo "2.sh \ $ A is $"

Running result:

Root @ James-desktop:/opt/Qt-everywhere/Marvell/APP/applications/factory-Roast #./1.sh
PID for 1.sh: 8152
1. Sh $ A is B
Using fork...
PID for 2.sh: 8153
2. Sh get $ A = B from 1.sh
2. Sh $ A is C
PID for 1.sh after run 2.sh: 8152
1. Sh $ A is B

 

Root @ James-desktop:/opt/Qt-everywhere/Marvell/APP/applications/factory-Roast #./1.sh Source
PID for 1.sh: 8158
1. Sh $ A is B
Using source...
PID for 2.sh: 8158
2. Sh get $ A = B from 1.sh
2. Sh $ A is C
PID for 1.sh after run 2.sh: 8158
1. Sh $ A is C

 

Root @ James-desktop:/opt/Qt-everywhere/Marvell/APP/applications/factory-Roast #./1.sh Exec
PID for 1.sh: 8159
1. Sh $ A is B
Using exec...
PID for 2.sh: 8159
2. Sh get $ A = B from 1.sh
2. Sh $ A is C

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.