On Wed, 20 Feb 2013 12:20:35 +0000 (UTC),
gaz...@shell.xmission.com (Kenny
McCormack) wrote:
> Suppose I am in a shell script and I want to know the full path to the
> script. Ignore, for the time being, the usual noises about how this is a
> bad idea, you shouldn't want or need to do this, etc, etc.
>
> Note that, under Linux, I can use /proc/self/exe to get the full path to
> the interpreter (/bin/bash, or whatever), but I am interested in the
> script itself.
>
> Feel free to answer this under any or all of the following conditions (or
> any other that you can think of...):
>
> 1) Portable (I.e., works on any normal system/shell, even on systems where
> /bin/sh isn't a "standard" shell [e.g., Solaris])
>
> 2) POSIX (I.e., assume a "standard" shell)
>
> 3) Bash
>
> 4) Zsh
>
> 5) Linux (I.e., you can take advantage of Linux-specific things,
> e.g., /proc)
If you skip the "it's a bad idea", "don't do this" etc. parts, there's a