![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Bash copy file contents into an existing file at a specific location | gshepherd7 | Shell Programming and Scripting | 6 | 03-11-2009 09:26 AM |
| Exit from sourced script | angad.makkar | Shell Programming and Scripting | 2 | 03-04-2009 06:35 AM |
| copy files from one location to similar location | pharos467 | UNIX for Advanced & Expert Users | 1 | 09-21-2008 12:21 PM |
| which file is sourced by bash on login (Mac OS X 10.5.3)? | Alex_Land | OS X (Apple) | 2 | 07-11-2008 10:52 PM |
| What is the file location? | Chanakya.m | Shell Programming and Scripting | 5 | 07-17-2006 12:42 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
The sample scripts below, I am looking for the location of the sourced b.sh file. The b.sh file is source by multiple files, so it is not feasible to rely on a "global" variable or passed argument. Is there any way to determine the location of b.sh within b.sh?
a.sh Code:
#!/bin/ksh
echo "a: <$0>"
ScriptDir=`dirname $0`
. ${ScriptDir}/b.sh
b.sh Code:
#!/bin/ksh
WhereAmI="????"
echo "b: <$0> ${WhereAmI}"
|
| Bits Awarded / Charged to vgersh99 for this Post | |||
| Date | User | Comment | Amount |
| 07-01-2009 | Anonymous | N/A | 1 |
|
||||
|
RE: KSH - Sourced file location
Thanks for the response, but as you indicate at the end of your post, it only works when a and b are in the same directory. My useCase has to address the notion that a is in a different directory and not necessarily always a.
The useCase is that /app1/a.sh sources /common/b.sh /app2/c.sh sources /common/b.sh I need b.sh to know that he is in the common directory. |
|
||||
|
RE: KSH - Sourced file location
Not really much help. The link tried to provide workarounds rather than answering the question. There are times when inside the script, it doesn't know what directory it is in. Seems like a $0 equivalent should be available for a sourced file.
|
|
|||||
|
Quote:
But it ($0 in the sourced shell) is not what what it's in the 'called' (not sourced) script - as the 'sourced' script runs in the same process space (there's no newly forked process) as the 'sourcing' script. Therefore, the '$0' in the sourced script is the '$0' of the sourcing script. I'm not sure if I'm explaining this correctly - you can take a look at this thread or browse this comp.unix.shell user group for similar threads. Last edited by vgersh99; 07-01-2009 at 05:14 PM.. |
|
||||
|
RE: KSH - Sourced file location
Understand it completely.
Again, I was looking (hoping) for a $0 equivalent for the sourced file. I realize the $0 is the invoked script. Thanks for the reponses, hopefully someone will provide some insight. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| ksh file directory |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|