0

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

5
  • You need to be using double quotes in your eval, not single quotes. Commented Apr 1, 2011 at 7:14
  • 3
    Your perl file doesn't need to end in .pl: Perl doesn't care. Just use #!/usr/local/bin/perl -w at the top of a file called package. File name suffixes are really just a Dos/Windows thing Commented Apr 1, 2011 at 7:21
  • Still seems to throw the same error. Commented Apr 1, 2011 at 7:28
  • Where really is your perl executable? /bin/perl or /usr/local/bin/perl? Commented Apr 1, 2011 at 8:07
  • @Rafe Kettler, Single quotes are fine if /bin/sh is really sh or compatible with sh (like bash). Commented Apr 1, 2011 at 18:30

2 Answers 2

2

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

cp package.pl package
chmod +x package

Run it:

package

or:

./package
Sign up to request clarification or add additional context in comments.

1 Comment

or alias it, if you're on *NIX.
2

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";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.