Home > Blockchain >  Get full call of Perl script with parameters
Get full call of Perl script with parameters

Time:05-24

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.

CodePudding user response:

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.

  •  Tags:  
  • perl
  • Related