Discussion Locked

Which script am I actually running

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I need a UNIX command that when called from a script will allow me to know which directory the script is being run from. Our versioning for production and test is simply to use different directory path. If I use which, it will simply tell me which one is in my path first. Right now I use pwd. The problem with pwd is that it will only tell me where it was called from. I want the script to be able to be called from anywhere. I have tried to compensate for that by checking $0 as well, but that will backfire if someone calls the test script from the production path. This is a ksh script.

3 replies

by ghislain.levesque

type script_name or which script_name

assign the result to a variable and then used dirname to get the path from where it is run from.

This discussion is closed to new replies.