[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

BASH_ENV and $0

From: Tapani Tarvainen
Subject: BASH_ENV and $0
Date: Thu, 22 Jul 2021 16:06:44 +0300

Hi all,

I would like to have a different initialization for scripts depending
on their name, without changing the scripts themselves. Specifically,
it should depend on a possible .-separated suffix in the filename.

I thought it would be easy, just put BASH_ENV=~/.bashenv in .bashrc
and then in .bashenv do

case "$0" in
  *.x) ... ;;
  *.y) ... ;;

But that does not work: it turns out that $0 is always "/bin/bash" in
.bashenv (or just "bash" if called as "bash script"). Apparently $0 is
only set to the script name after .bashenv has been processed, and it
isn't in any other environment variable either.

Is this intentional or a bug?

But, more important, is there a way to determine the script name
within .bashenv?

Tapani Tarvainen

reply via email to

[Prev in Thread] Current Thread [Next in Thread]