How to get running Perl script path and name (argv [0] in C)

In C / C ++ (bash too?), The first argv [0] command line argument is the binary file name (prefixed with an absolute or relative path that the user calls).

In Perl, the first command line argument $ ARGV [0] is the first command line argument after the path and script name.

How can a Perl script get the path and name that were used to call it?

Thank!

+3
source share
2 answers

"In C / C ++ (bash too?), The first command line argument, argv [0], is the binary file name"

Incidentally, it’s wrong. The ISO standard does not provide for such a thing.

From C99:

argc , , argv [0], ; argv [0] [0] , .

, , " ", " ". , , :

... argv [0] argv [argc-1] , , , . "

argv[0] "sleep 60" " " pax fantastic sleep ", " /bin/sleep ".

, , , .


, , Perl $0 $PROGRAM_NAME ( "" ) . . perlvar.

+6

$0 , perl script.

+7

Source: https://habr.com/ru/post/1753244/


All Articles