chamilad
chamilad

Reputation: 1669

Get working directory of the parent shell from a child process

I'm calling /location2/script2.sh from /location1/script1.sh. Is there a method to figure out location1 from script2.sh?

bash /location2/script2.sh

Upvotes: 1

Views: 117

Answers (1)

heemayl
heemayl

Reputation: 42107

Yes, just use $PWD or pwd.

If you call /location2/script2.sh from /location1/script1.sh, then the current working directory of script2.sh will always be /location1, not /location2.

Upvotes: 3

Related Questions