In PERL , $0 variable displays program name ( if we use inside script) .likewise is there a way to display program name and it's arguments passed to script .
e.g.
test.pl -a1 -b3 -c4
inside test.pl , if I use $0 , it gives me test.pl ..but I am looking for command to get complete program name and arguments passed.
Thanks
$ cat tester
#!/bin/bash
# scipt name
echo "script name ${0##*/}"
# all arguments
echo "all arguments $*"
# argument count
echo "argument count $# "
# first argument
echo "First argument $1"
# second argument
echo "second argument $2"
# last argument
last=$#
echo "last argument ${!last}"
$ bash tester 1 2 3 4
script name tester
all arguments 1 2 3 4
argument count 4
First argument 1
second argument 2
last argument 4
---------- Post updated at 12:55 AM ---------- Previous update was at 12:45 AM ----------
In case of perl
$ cat test.pl
#!/usr/bin/perl
my $c = 1;
# script name
my $script = $0;
# count
my $argsc = $#ARGV + 1;
print "Total args passed to $script : $argsc \n";
# array @ARGV
foreach my $t(@ARGV) {
print "Arg # $c : $t\n";
$c++;
}
$ perl test.pl 1 2 3 4
Total args passed to test.pl : 4
Arg # 1 : 1
Arg # 2 : 2
Arg # 3 : 3
Arg # 4 : 4