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开发者_JAVA百科 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
Change to the name you want to use and make it executable:
cp package.pl package
chmod +x package
Run it:
package
or:
./package
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";
精彩评论