in reply to Different meanings of $0 under the same operating system

...all of which can be summarised as: $0 represents the path by which *NIX locates the script

Furthermore, there is yet a 4th possibility - normally only noticed under one of the std *NIX shells whereby, if a script is 'dot'ted or 'source'ed, $0 is the name of the shell in which the 'dot'/'source' command is run - the perl equivalent of which is to do knowthyself from another script.

A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re^2: Different meanings of $0 under the same operating system
by Jorge_de_Burgos (Beadle) on Nov 03, 2009 at 18:51 UTC
    ...all of which can be summarised as: $0 represents the path by which *NIX locates the script
    I agree. Maybe we should promote a change in the perlvar definition of $0 I quoted at the very beginning of this node ("the name of the program being executed")?
Re^2: Different meanings of $0 under the same operating system
by JavaFan (Canon) on Nov 03, 2009 at 21:54 UTC
    ...all of which can be summarised as: $0 represents the path by which *NIX locates the script
    Except of course when it doesn't.
    $ perl < knowthyself My name is -...
      Ahh, but it is ... since, when used as a file name, '-' is an alternative id for stdin - witness most of the *NIX filter commands e.g. sort, join et al

      A user level that continues to overstate my experience :-))
        That many *NIX filter commands take '-' to be STDIN is an application convention. It's not something either the OS, or any of the standard libraries treat as special. In perl < foo, - isn't passed as an argument to any function of the exec family. It's not UNIX that is 'locating' the script.

        I don't see your point. Are you saying opening '-' should give me the script, or are you saying that opening '-e' would normally give me the command line arguments?

        >perl -le"print $0" -e >perl -lE"print $0" -e