Re: bash scripts: how to determine directory of 'source'd file
- From: "Jan C. Nordholz" <jckn@xxxxxxx>
- Date: Tue, 31 Jan 2006 22:59:41 +0100
On Tue, Jan 31, 2006 at 09:26:21PM +0000, michael wrote:
> On Tue, 2006-01-31 at 10:16 -0500, Juergen Fiedler wrote:
> > On Tue, Jan 31, 2006 at 02:26:27PM +0000, michael wrote:
> > > Presuming I have a file setEnvVars.sh that I wish to source,
> > > . path/setEnvVars.sh
> > > How do I, within the script, determine the actual directory within which
> > > the setEnvVars.sh file sits? The sourcing seems to disallow me access to
> > > $0 etc
> > >
> > > thanks, M
Hi Michael,
perhaps ${BASH_ARGV[0]} can help you?
] jcn@hejre:~/tmp$ cat ../X.sh
] #!/bin/bash
] set | grep BASH_ARG
] jcn@hejre:~/tmp$ ../X.sh
] BASH_ARGC=()
] BASH_ARGV=()
] jcn@hejre:~/tmp$ . ../X.sh
] BASH_ARGC=([0]="1")
] BASH_ARGV=([0]="../X.sh")
] jcn@hejre:~/tmp$ cd ..
] jcn@hejre:~$ cd tmp
] jcn@hejre:~/tmp$ . ../X.sh
] BASH_ARGC=([0]="1")
] BASH_ARGV=([0]="../X.sh")
BASH_ARG[CV] carry the argument lists of the subroutine calls currently on
the execution stack - and 'source' (or '.') qualifies as a subroutine, so
its argument (the filename to be sourced) is on the stack. This, in combination
with $(pwd), should be sufficient to locate the sourced file.
HTH,
Jan
--
Jan C. Nordholz
<jckn At gmx net>
Attachment:signature.asc
Description: Digital signature
- References:
- bash scripts: how to determine directory of 'source'd file
- From: michael
- Re: bash scripts: how to determine directory of 'source'd file
- From: Juergen Fiedler
- Re: bash scripts: how to determine directory of 'source'd file
- From: michael
- bash scripts: how to determine directory of 'source'd file
- Prev by Date: mozilla-browser -> seamonkey
- Next by Date: Re: wrong RE: Not a Debian question, but you guys know this stuff...
- Previous by thread: Re: bash scripts: how to determine directory of 'source'd file
- Next by thread: Re: bash scripts: how to determine directory of 'source'd file
- Index(es):
Relevant Pages
- Re: Problems with a modems under linux
... PACKAGEDIR/scripts/debian/slmodemd script or do I use the ... Debian boxes
at work are all running on 32-bit hardware. ... but I don't think you point pppd at that
device. ... Oh well, HTH, ... (comp.os.linux.portable) - RE: Mistake in MSDN
... > own client-side javascript function and then it will call a javascript ...
> HTH, Jakob. ... >> script is called. ... >> Now in my case,
its always the client side script which calls first, no ... (microsoft.public.dotnet.framework) - Re: Certain website keep getting error message when trying to contact them
... It looks like the guys at cunard.com have a bug in their submit script. ...
should contact them via email and ask them to fix it. ... (microsoft.public.windows.inetexplorer.ie6.browser) - Re: Problems with cron
... Try sourcing the user's profile at the top of your script. ... HTH
... David ... (AIX-L) - Re: smartnavigation doesnt work!
... from the .net framework install directory. ... HTH, ... >ive
set smartnavigation to true for my asp application page in its property ... >html displayed
i can see the smartnav.js script included: ... (microsoft.public.dotnet.framework.aspnet)