This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project. See the Cygwin home page for more information.
[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index] [Subject Index] [Author Index] [Thread Index]

nesting "source" scripts




This looks like it is simply a bash bug rather than anything specific
to cygwin but snce I encountered this using cygwin I will try to find
the answer here first.

It looks like the full path name of bash scripts is not available when
they are invoked with "source".  This makes it impossible to call
other scripts in the same directory, no?

Consider the two bash scripts in the same directory, A.sh and B.sh

A.sh --
	#!bash
	echo A: $0
	source B.sh
B.sh -- 
	#!bash
	echo B: $0
	echo Inside of B!

If CWD (current working directory) is the same as the location of 
A.sh and B.sh, you can simply type

	$ source A.sh
	A: bash
	B: bash
	Inside of B!

and it will all work.

However, if CWD is someplace else, and you type

	a/long/path/A.sh

it seems there is no way for A.sh to correctly find the B.sh script
without hardcoding the path into A.sh.

You might think you would simply take the directory component of $0
and use that to help find the full path of A.sh.  That does not work
because when invoking a script with "source" (and only then!) $0 is
always set to just "bash", not the path of script.

Thus as far as I can tell there is no way to nest scripts that might
be invoked with "source", short of hardcoding paths.  Is this true?
If so, it sure seems like a bug.

-csw


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com