Skip to content

Instantly share code, notes, and snippets.

@kanonji
Last active August 15, 2016 11:52
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 kanonji/f8debe058a74304de17880940df8bcc6 to your computer and use it in GitHub Desktop.
Save kanonji/f8debe058a74304de17880940df8bcc6 to your computer and use it in GitHub Desktop.
Test to share variables within two script.
#!/bin/sh
echo " #${0} begin"
echo " echo \$WORKING_DIR"
echo " ${WORKING_DIR}"
echo " #${0} end"
#!/bin/sh
echo "#${0} begin"
echo "WORKING_DIR=\$(cd \$(dirname "\${0}"); pwd)"
WORKING_DIR=$(cd $(dirname "${0}"); pwd)
echo "./callee.sh"
./callee.sh # Run in subshell. The variable not shared.
echo "source callee.sh"
source callee.sh # The variable shared.
# . callee.sh # Same as source
echo "#${0} end"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment