Skip to content

Instantly share code, notes, and snippets.

@jitpaul
Last active September 17, 2018 02:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jitpaul/7cdadc36565035c47c2a077b620e20c1 to your computer and use it in GitHub Desktop.
Save jitpaul/7cdadc36565035c47c2a077b620e20c1 to your computer and use it in GitHub Desktop.
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