Fixing bash script bogosity - help?

Ignacio Vazquez-Abrams ivazqueznet at gmail.com
Tue Apr 28 07:19:03 EDT 2009


On Tue, 2009-04-28 at 13:07 +0200, Martin Langhoff wrote:
> On Tue, Apr 28, 2009 at 1:01 PM, Ignacio Vazquez-Abrams
> <ivazqueznet at gmail.com> wrote:
> > Which part of the following doesn't work?
> 
> Just test your minimal 3 line script with the example input I've given
> you. It breaks:
> 
> # cat > sample.sh
> #! /bin/bash
> 
> CMD=(touch "$@")
> bash -c "${CMD[@]}"
> # ./sample.sh "this is file one" "this is file two" "file
> >
> # bash -x ./sample.sh "this is file one" "this is file two" "file \" f"
> + CMD=(touch "$@")
> + bash -c touch 'this is file one' 'this is file two' 'file " f'
> touch: missing file operand
> Try `touch --help' for more information.
> 
> Bash (line runuser) expects a line of shell, quoted/escaped
> appropriately, as a single string param -c
> 
> *that* is the challenge.

Ah, I see now.

Try this:

bash -c 'touch "$@"' "${CMD[@]}"

Or in the case of the full script:

bash -c "$ERL"' "$@"' "${ERL_COMMAND[@]}"

-- 
Ignacio Vazquez-Abrams <ivazqueznet at gmail.com>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <http://lists.laptop.org/pipermail/devel/attachments/20090428/98be7910/attachment.sig>


More information about the Devel mailing list