[vox-tech] Bash question

Mitch Patenaude vox-tech@lists.lugod.org
Mon, 29 Sep 2003 08:55:22 -0700


On Monday, Sep 29, 2003, at 08:35 US/Pacific, Jay Strauss wrote:
> I want to source a script from my .bashrc.   When that sourced file 
> starts
> to run I want it (the sourced file) to learn its location on the 
> filesystem.
> Normally $0 contains the full path and name of the file being run.  
> But in a
> login or su, $0 contains -bash or -su (respectively).

This isn't quite true... $0 is set properly if run as a true "subscript"
with it's own shell, like so:

/opt/myapp/bin/config

But by putting that . in the front you're running the script "inline",
which is to say in the same shell.  The reason for doing this is usually
to allow the script to preserve modifications to things like environment
variables which would be lost when the subshell exits.

The only thing special about login rc scripts if the '-' at the 
beginning of
$0 and that they transfer control to the terminal when they're done.  
Other
than that, they're like any other shellscript.

   -- Mitch