Hi! I wanted to run the system command with in Perl script to execute
shell script with argument. I need to know the correct syntax for the
arguments.
Ex.)
#/opt/bin/perl
system("shellscript.sh" <arg1>, <arg2> <arg3>);
I am getting syntax error. If i get rid of the arg1-3 then the shell
script runs just fine.
Are you using commas exactly as shown? If so, that's probably the
problem. Try this instead:
system("foo.sh", "bar", "baz", "qux");
. . where bar, baz, and qux are your arguments. You could also simply
do something like one of the following:
system("foo.sh bar baz qux");
my $foo = "foo.sh";
my @args = qw(bar baz qux");
system("$foo @args");
my @command_and_args = qw(foo.sh bar baz qux);
system("@command_and_args");
In each case, assuming the use of system() is the only thing on that
line of the program, the parentheses are optional.
You *are* using the strict and warnings pragmas -- right? You should
always include the following two lines at the beginning of any Perl
script while working on it to help with debugging and good programming
practice:
use strict;
use warnings;
You should also make use of perldoc, which should be installed on your
system. With the -f option, the perldoc command can be used to look up
information about a specific function. In this case, you can learn more
about how system() works with the following commmand, for instance:
perldoc -f system
I hope that helps.