-
-
Save gwpantazes/d71bf815f20ca7605284f53b5378f90a to your computer and use it in GitHub Desktop.
Running scripts from other directory
This file contains hidden or 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
echo "a.sh is run" | |
pwd | |
echo "" | |
echo "First B" | |
# Doesn't work if in a different directory | |
source b.sh | |
echo "" | |
echo "Second B" | |
# DOES work from different directory | |
source $(dirname "$0")/b.sh |
This file contains hidden or 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
echo "b.sh is run" | |
pwd | |
echo "Script location: $0" |
This file contains hidden or 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
user:~$ echo $HOME | |
/Users/user | |
user:~$ ls | |
test/ | |
user:~$ cd test | |
user:~/test$ ./a.sh | |
a.sh is run | |
/Users/user/test | |
First B | |
b.sh is run | |
/Users/user/test | |
Script location: ./a.sh | |
Second B | |
b.sh is run | |
/Users/user/test | |
Script location: ./a.sh | |
user:~/test$ cd ~ | |
user:~$ test/a.sh | |
a.sh is run | |
/Users/user | |
First B | |
test/a.sh: line 7: b.sh: No such file or directory | |
Second B | |
b.sh is run | |
/Users/user | |
Script location: test/a.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment