bash.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
name1="test1" | |
export name2="test2" | |
{ typeset name3="test3"} #This is a local variable. It cannot be accessed outside the braces. | |
(echo $name1) #This is executed in a sub-shell. Hence prints 'name1' | |
(echo $name2) #This is executed in a sub-shell. Hence prints 'name2' | |
(echo $name3) #This is executed in a sub=shell. It does not have access to the local variable 'name3' | |
./script2.sh #script2.sh is executed as a sub-process. Can only print 'name2' | |
. script2.sh #script2.sh is sourced into the current script. Can print name1, name2 | |
source script2.sh #script2.sh is sourced into the current script. Can print name1, name2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment