bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: converting array to string by quoting each element for eval


From: Chris F.A. Johnson
Subject: Re: converting array to string by quoting each element for eval
Date: Tue, 15 Nov 2011 18:18:01 -0500 (EST)
User-agent: Alpine 2.00 (LMD 1167 2008-08-23)

On Tue, 15 Nov 2011, Peng Yu wrote:

  Why not use the array instead of making it into a single string?

$cmd "address@hidden"

  Why are you using eval or quotearg.sh? It sounds as if you are
  making the process more complicated than it need be.

For the examples that I gave, probably it is not necessary.

I'm yet to make a concrete complex example to demonstrate its
usefulness in practice. But I think that it is easy to imagine that
there will be some complex commands that are composed by concatenating
multiple strings to be evaled, in which case this may be useful.

    It may be possible to come up with something, but I doubt that
    there are many cases where the direct use of an array is not more
    appropriate (unless you need portability, in which case you
    wouldn't be using arrays in the first place).

    In any case, combining a command and its arguments in a single
    string is almost always the wrong way to go about it.

--
   Chris F.A. Johnson, <http://cfajohnson.com/>
   Author:
   Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]