Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Location of sourced ksh script

Status
Not open for further replies.

xjc539w

IS-IT--Management
Aug 5, 2003
11
0
0
US
Any thoughts on determining the location of a sourced script?

I have a.sh in /usr/home/location1 that calls b.sh in /usr/home/location2.

/usr/home/location1/a.sh
echo $0
. /usr/home/location2/b.sh

/usr/home/location2/b.sh
echo $0

When you run this script the output is:
/usr/home/location1/a.sh
/usr/home/location1/a.sh

Is there another system variable or thought to yield, the location of b.sh?

Thanks
 
Perhaps by using lsof -p $$ and looking for FD 0? (I am not at an AIX box at the moment so I can't try this)


HTH,

p5wizard
 
Thanks for the response, however lsof is not installed on the servers. Probably not an option here to download on to a production server.
 
Well, one workaround is to have your script "remember" where it's at...

Code:
SCRIPT=/path/to/location1/a.sh
# or maybe SCRIPT=$0 ???

(do stuff in a.sh)

# source b.sh script, save the pathname of b.sh for use within the script
CALLINGSCRIPT=${SCRIPT} # save for future use
SCRIPT=/path/to/location2/b.sh
# you may reference variable SCRIPT inside b.sh
. ${SCRIPT}

# reset SCRIPT variable to initial value
SCRIPT=${CALLINGSCRIPT}

(do some more stuff back in a.sh)

HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top