Neeraj
Neeraj

Reputation: 8532

Calling a perl script as a shell command

I want to call my perl script as a command from command line. Example lets say I have a perl file like following

#!/usr/local/bin/perl -w
@args =("mvn","package");
    system(@args) == 0
    or die "system @args failed"

I right not call this using package.pl

I tried doing the following

#!/bin/sh
  eval 'exec /bin/perl –x -S $0 ${1+"$@"}'
    if 0; 
#!/usr/local/bin/perl -w
@args =("mvn","package");
    system(@args) == 0
    or die "system @args failed"

and then name the file 'package' .Do chmod on package

When I try to run package, then I get the error "Can't open perl script []x:No such file or directory

Can someone please point me out , as to how to do this properly??

Thanks

Neeraj

Upvotes: 0

Views: 2075

Answers (2)

tadmc
tadmc

Reputation: 3744

Change to the name you want to use and make it executable:

cp package.pl package
chmod +x package

Run it:

package

or:

./package

Upvotes: 2

Francisco R
Francisco R

Reputation: 4048

Changed single quotes to double quotes and escaped inner double quotes. Also, there seems to be some problem with paths. Try calling your script with absolute path. I tried adding "./" and it worked:

#!/bin/sh

echo "This is shell"

eval "exec /usr/bin/perl -x -S ./$0 ${1+\"$@\"}"
   if 0;

#!/usr/bin/perl -w
print "This is Perl\n";

Upvotes: 2

Related Questions