Skip to content

Instantly share code, notes, and snippets.

@jitpaul

jitpaul/script1.sh Secret

Last active Sep 17, 2018
Embed
What would you like to do?
bash.sh
#!/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