[PLUG] Perl - Passing my script's arguments to another program

Jeme A Brelin jeme at brelin.net
Mon Mar 22 14:13:02 UTC 2004


On Mon, 22 Mar 2004, Evan Heidtmann wrote:
> On Mon, 2004-03-22 at 12:41, Jeme A Brelin wrote:
> > This may turn out to be one of those utterly pointless and frustrating
> > responses we see on this list sometimes, but I have to ask.
>
> Not the case. Thanks for asking.

Yeah, this isn't a particulary perly task.  It'd probably faster to just
run it in a shell.

> I do know that, in bash, $* is the arguments passed to the script. So I
> tried this (the exernal program is metacam, my script is script.pl):
>
> #!/bin/bash
>
> metacam -ax $* > /tmp/metacam-tmp.xml
>
> script.pl /tmp/metacam-tmp.xml
>
> Then script.pl will read the file $ARGV[0] for further processing.
>
> But even this breaks when the filenames passed to the bash script
> contain spaces.
>
> So now my question is broader: How do I pass args to a command of this
> form:
>
> command $ARGS > filename
>
> in any language?

Here's a quickie bash way of doing it:

for file in "$@"; do
    command "$file" >output_from_"$file";
done

Dig that?  You quote the variable instances so that the literal characters
in the variables are used instead of splitting on the spaces or what have
you.

Season to taste.

J.
-- 
   -----------------
     Jeme A Brelin
    jeme at brelin.net
   -----------------
 [cc] counter-copyright
 http://www.openlaw.org




More information about the PLUG mailing list