In C / C++ (bash, too?) the first command-line argument, argv[0], is the binary filename (prefixed by an absolute or relative path as invoked by the user).
In Perl the first command-line argument $ARGV[0] is the first command-line argument after the path and name of the script.
How can a Perl script get the path and name that was used to invoke it?
Thanks!
is dead wrong, by the way. The ISO standard mandates no such thing.
From C99:
And notice that it states “represents the program name”, not “is the location of the binary executable”. That’s because there’s an earlier snippet which states:
It’s quite legal for your
argv[0]for the command “sleep 60” to be “pax’s fantastic sleep utility” rather than “/bin/sleep”.In short, the environment doesn’t have to provide a representation of the program and, even if it does, it doesn’t have to be anything usable for locating the binary.
But, having bored you with my diatribe, Perl provides
$0or$PROGRAM_NAME(in that hideous “English” mode) for this purpose. See perlvar for details.