Re: echo $BASH_SOURCE in Test_Bash_2.sh
Keith Marshall <[email protected]>
| Newsgroups | gmane.comp.gnu.mingw.msys |
|---|---|
| Organization | MinGW Project Administrator |
| Message-ID | <[email protected]> |
Hi Stephen,
Please consider migrating to MinGW-users; I'd like to deprecate this
list. Thanks.
On Wednesday 18 March 2009 00:55:16 Stephen Grant Brown wrote:
> In Test_Bash_2.sh
>
> I have
>
> echo $LINENO
> echo $BASH_SOURCE
> echo $LINENO
> pwd
> echo $LINENO
>
> The following is the output of a msys shell
>
> $ Test_Bash_2.sh
> 1
>
> 3
> /src
> 5
And you expected to see `./Test_Bash_2.sh', rather than that blank
line between `1' and `3'? I can't reproduce this; I see:
$ uname -orv
1.0.11(0.46/3/2) 2009-01-29 00:39 Msys
$ sh --version
GNU bash, version 3.1.0(1)-release (i686-pc-msys)
Copyright (C) 2005 Free Software Foundation, Inc.
$ cat > foo.sh <<\EOF
> #!/bin/sh
> echo $LINENO
> echo $BASH_SOURCE
> echo $LINENO
> pwd
> echo $LINENO
> EOF
$ foo.sh
2
./foo.sh
4
/home/keith
6
(Note that I added a shebang, which accounts for the line number
differences, but the result is similar without it).
> I am using msys on a Windows XP machine
What versions of MSYS, and bash?
> Under cygwin on a Windows ME machine I see the Test_Bash_2.sh
> filename printed.
FWIW, I see the same on my Ubuntu-8.04-LTS box, but I also see it in
the latest MSYS-1.0.11 snapshot, on Win2K, with bash-3.1.0(1).
> Why am I not seeing it on this machine?
Perhaps you are using an older version of bash? In any case, I'd
caution against using $BASH_VERSION in this fashion; see:
$ man bash
:
BASH_SOURCE
An array variable whose members are the source filenames
corresponding to the elements in the FUNCNAME array variable.
:
FUNCNAME
An array variable containing the names of all shell functions
currently in the execution call stack. The element with index
0 is the name of any currently‐executing shell function. The
bottom‐most element is "main". This variable exists only when
a shell function is executing. ...
Note that $BASH_SOURCE is an array variable, and it is related to the
$FUNCNAME array variable, which is empty (undefined) when not within
the scope of execution of a shell function. Thus, the behaviour you
see, (i.e. $BASH_SOURCE is empty), actually seems to me to be more
consistent with the documentation.
If you want the file name for the current script, get it from $0.
--
Regards,
Keith.
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Mingw-msys mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-msys