elgringoloco
elgringoloco

Reputation: 15

Get full call of Perl script with parameters

How can I get the file name and input parameters of the script into a variable?

So it should look like this:

# Start script as such: ./myscript.pl -d -s server1.domain

#!/usr/bin/perl
use strict;
use warnings;

my $call = some_command;

print $call; # Output: myscript.pl -d -s server1.domain 
             # OR ./myscript.pl -d -s server1.domain 
             # OR /path/to/myscript.pl -d -s server1.domain

Tried doing this with __FILE__ and $0 but I can't seem to get the input parameters in the variable.

I'm running v5.10.1 on a AIX machine.

Upvotes: 0

Views: 108

Answers (1)

ikegami
ikegami

Reputation: 385647

The program and its args are found in $0 and @ARGV respectively.

You can use String::ShellQuote's shell_quote to form a command line from them.

Upvotes: 5

Related Questions