shell script to call perl script problems

Ok, don't ask me why, but all calls to perl must be called by a shell script. Its really not ideal, but its what I have to work with.

Calling it isnt the issue, its passing in the arguments.

I have about 1000 perl scripts to call by a shell script. Right now, I'm executing the shell script and bringing in the entire perl script and its arguments as one string to be executed.

The shell script is simply

$*

However, when I call a perl script with its arguments, its fails many times because of the way the shell script is resolving the passed arguments. For example. Here's the shell script (callperl.sh) executing a perl script:

 
callperl.sh zipfile.pl "/tmp/last/done*.txt"

When it gets executed by the shell script, the parameter of "/tmp/last/done*.txt" gets resolved as all the files that matches the regex. This caused the perl script to failed because its exepecting the argument "tmp/last/done*.txt" and not a list of files. The

I've tried to encapsulate the arguments in various double quotes, tick marks, single quotes, etc. but cannot get the proper results.

 
callperl.sh zipfile.pl ""/tmp/last/done*.txt""
callperl.sh zipfile.pl \"/tmp/last/done*.txt\"
callperl.sh zipfile.pl '"/tmp/last/done*.txt"'
callperl.sh `zipfile.pl "/tmp/last/done*.txt"`

I'd like to have a single shell script that could call a perl scripts with any number of arguments, but have it resolve the arguments correctly because the number of arguments varies greatly. Not only that, but there are over 1000 perl scripts that need to be called this way. Is there a simple way to do this? What am I missing?

Try

#!/usr/bin/env ksh
"$@"

This should preserve any quoting that was done on the original command line. Assuming Ksh; bash might but untried.

1 Like

Thanks! So far so good! :b:

Can you explain to me the difference between

$*

and

"$@"

The $* I assumed took the entire string after the shell script and executed it. I've never used @ before.

quoting from the Advanced Bash-Scripting Guide

refer to their example for more details

2 Likes