On Sat, 2024-Feb-17, Zachary Santer wrote:
On Fri, Feb 16, 2024, Marc Aurèle La France wrote:
On Fri, 2024-Feb-16, Zachary Santer wrote:

And you're sure ${BASH_SOURCE[0]} wasn't what you wanted all along?

Yes, but that doesn't matter now.

At the bottom of my .bashrc file:
printf '%s\n' "Hello, this script is ${BASH_SOURCE[0]}"

I start a new terminal and get:
Hello, this script is /home/zsant/.bashrc

How is this not what you wanted?

Do ...

rm -fr GREPME grepme
echo '#! /bin/bash\nset' > GREPME
"ln" GREPME grepme
chmod a+x grepme

... then (case matters) ...

BASH_ENV=GREPME ./grepme | fgrep -iw grepme

... gives ...

BASH_ARGV=([0]="GREPME")
BASH_ENV=GREPME
BASH_SOURCE=([0]="GREPME")
_=./grepme
BASH_ENV=GREPME
BASH_SOURCE=([0]="./grepme")

... so $_ wins, not $BASH_SOURCE[0]

Marc.

Reply via email to