parlays
asked on
BASH script, get the script directory
Hello!
I am running a shell script from within another shell script. They are in different directories and wanted to know the best way to get the current directory that the sub shell script is running from.
I've tried using:
$(dirname $0)
PWD
But those show the location of the original shell script. Every command seems to act as if it is in the original shell script.
I am calling the second shell script from the first using the '.' dot command. Any advice is appreciated.
thanks!
I am running a shell script from within another shell script. They are in different directories and wanted to know the best way to get the current directory that the sub shell script is running from.
I've tried using:
$(dirname $0)
PWD
But those show the location of the original shell script. Every command seems to act as if it is in the original shell script.
I am calling the second shell script from the first using the '.' dot command. Any advice is appreciated.
thanks!
as mentioned by arnold the current working directory or the present working directory will not change unless you change it! If you want the location of the script called then it will be the current directory plus the relative path to the script or if the script is in the set PATH then the command
basedir `which command`
OR
basedir which scriptname`
should give the dir name in which the command or script is in.
basedir `which command`
OR
basedir which scriptname`
should give the dir name in which the command or script is in.
typo
basedir `which scriptname`
basedir `which scriptname`
ASKER
Sweet! Thanks guys so much for the information. A quick follow up questions and I will award you guys points. Is there a difference between cd and chdir or is one just an alias?
ASKER
I've requested that this question be closed as follows:
Accepted answer: 300 points for arnold's comment #a38359563
Assisted answer: 200 points for omarfarid's comment #a38359584
Assisted answer: 0 points for parlays's comment #a38359667
for the following reason:
thanks!
Accepted answer: 300 points for arnold's comment #a38359563
Assisted answer: 200 points for omarfarid's comment #a38359584
Assisted answer: 0 points for parlays's comment #a38359667
for the following reason:
thanks!
they are the same
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks!
Since the scripts seem to be running without an issue, it sounds as though explicit and full paths are being used.