# Shell script with arguments within perl script

**URL:** <https://www.ruby-forum.com/t/shell-script-with-arguments-within-perl-script/103205>\
**Category:** Ruby\
**Created:** [May 2, 2007, 10:22pm UTC](https://www.ruby-forum.com/t/shell-script-with-arguments-within-perl-script/103205 "2007-05-02T22:22:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ed8c4c/32.png) [@jay](https://www.ruby-forum.com/u/jay)\
**Post date:** [May 2, 2007, 10:22pm UTC](https://www.ruby-forum.com/t/shell-script-with-arguments-within-perl-script/103205/1 "2007-05-02T22:22:53Z")

</div>

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” , );

I am getting syntax error. If i get rid of the arg1-3 then the shell  
script runs just fine.

thanks.

---

<div class="post-metadata">

**Author:** ![jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ed8c4c/32.png) [@jay](https://www.ruby-forum.com/u/jay)\
**Post date:** [May 2, 2007, 10:29pm UTC](https://www.ruby-forum.com/t/shell-script-with-arguments-within-perl-script/103205/2 "2007-05-02T22:29:18Z")

</div>

In message [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid), jay  
writes:

> 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.

Hmm.

I know it’s easy to mistake perl for ruby, what with both of them being  
sorta newfangled computer stuff, but…

> #/opt/bin/perl
> 
> system(“shellscript.sh” , );
> 
> I am getting syntax error. If i get rid of the arg1-3 then the shell  
> script runs just fine.

Well, yes.

And if this were a perl list, you may rest assured I’d tell you how to  
expand @ARGV for your purposes.

-s

---

<div class="post-metadata">

**Author:** ![jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ed8c4c/32.png) [@jay](https://www.ruby-forum.com/u/jay)\
**Post date:** [May 2, 2007, 10:54pm UTC](https://www.ruby-forum.com/t/shell-script-with-arguments-within-perl-script/103205/3 "2007-05-02T22:54:20Z")

</div>

On May 3, 2007, at 5:22 AM, jay wrote:

> script runs just fine.
> 
> thanks.
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

in Ruby:

system( command, arg, arg, arg)

Returns true if command runs successfully, false otherwise.

There is also:

exec( command, arg, arg, arg)

Exact behavior is platform dependent. One might presume that since  
Ruby borrows a fair amount from Perl, that there may be something  
similar going on.

---

<div class="post-metadata">

**Author:** ![jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ed8c4c/32.png) [@jay](https://www.ruby-forum.com/u/jay)\
**Post date:** [May 2, 2007, 11:31pm UTC](https://www.ruby-forum.com/t/shell-script-with-arguments-within-perl-script/103205/4 "2007-05-02T23:31:23Z")

</div>

On Thu, May 03, 2007 at 05:22:54AM +0900, jay wrote:

> 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.

---

<div class="post-metadata">

**Author:** ![jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ed8c4c/32.png) [@jay](https://www.ruby-forum.com/u/jay)\
**Post date:** [May 2, 2007, 11:33pm UTC](https://www.ruby-forum.com/t/shell-script-with-arguments-within-perl-script/103205/5 "2007-05-02T23:33:23Z")

</div>

On Thu, May 03, 2007 at 05:22:54AM +0900, jay wrote:

> 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.

Oh, one other thing – you’re asking this of a Ruby community, not a  
Perl community. Since this was apparently posted via the forum, rather  
than the mailing list or newsgroup, I suspect what you actually want  
is the PerlMonks website:

[http://www.perlmonks.org](http://www.perlmonks.org)

---

<div class="post-metadata">

**Author:** ![jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ed8c4c/32.png) [@jay](https://www.ruby-forum.com/u/jay)\
**Post date:** [May 3, 2007, 6:59am UTC](https://www.ruby-forum.com/t/shell-script-with-arguments-within-perl-script/103205/6 "2007-05-03T06:59:53Z")

</div>

On May 3, 2007, at 6:31 AM, Chad P. wrote:

> [http://www.perlmonks.org](http://www.perlmonks.org)
> 
> –  
> CCD CopyWrite Chad P. [[http://ccd.apotheon.org](http://ccd.apotheon.org) ]  
> Brian K. Reid: “In computer science, we stand on each other’s feet.”

[www.perlmonks.org](http://www.perlmonks.org) indeed!  
Good place for good Perl.

---

<div class="post-metadata">

**Author:** ![jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ed8c4c/32.png) [@jay](https://www.ruby-forum.com/u/jay)\
**Post date:** [May 3, 2007, 6:49am UTC](https://www.ruby-forum.com/t/shell-script-with-arguments-within-perl-script/103205/7 "2007-05-03T06:49:52Z")

</div>

On 5/2/07, Chad P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
When there are people behaving strangly in nice restaurants one can  
suspect that they are Critics (sp?) from Michelin or whatever  
Guide(1).  
Chad I guess you just got us our first “Toque” 😉

Cheers  
Robert

(1) Although that is probably never the case.

---

<div class="post-metadata">

**Author:** ![jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ed8c4c/32.png) [@jay](https://www.ruby-forum.com/u/jay)\
**Post date:** [May 3, 2007, 10:57am UTC](https://www.ruby-forum.com/t/shell-script-with-arguments-within-perl-script/103205/8 "2007-05-03T10:57:27Z")

</div>

On Thu, May 03, 2007 at 05:47:56PM +0900, Chad P. wrote:

> > (1) Although that is probably never the case.
> 
> Uh, what? What does a hat have to do with this?
> 
> I think you lost me.

Never mind. I get it – the purpose of the metaphor just slipped by me  
for a moment there.

Thanks for the compliment.

---

<div class="post-metadata">

**Author:** ![jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ed8c4c/32.png) [@jay](https://www.ruby-forum.com/u/jay)\
**Post date:** [May 3, 2007, 10:48am UTC](https://www.ruby-forum.com/t/shell-script-with-arguments-within-perl-script/103205/9 "2007-05-03T10:48:26Z")

</div>

On Thu, May 03, 2007 at 01:49:16PM +0900, Robert D. wrote:

> On 5/2/07, Chad P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
> When there are people behaving strangly in nice restaurants one can  
> suspect that they are Critics (sp?) from Michelin or whatever  
> Guide(1).  
> Chad I guess you just got us our first “Toque” 😉
> 
> Cheers  
> Robert
> 
> (1) Although that is probably never the case.

Uh, what? What does a hat have to do with this?

I think you lost me.
