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 21:03:17 -0500 (EST)
User-agent: Alpine 2.00 (LMD 1167 2008-08-23)

On Tue, 15 Nov 2011, Peng Yu wrote:

On Tue, Nov 15, 2011 at 6:43 PM, Chris F.A. Johnson
<chris@cfajohnson.com> wrote:
On Tue, 15 Nov 2011, Peng Yu wrote:

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

Please compare the two scripts and see if the second one makes more sense.

/tmp$ cat not_convert_args_to_string.sh
#!/bin/bash

options="$2"
find $1 $options
echo find $1 $options

 More sensible would be to have each option a separate argument and
 do:

location=$1
shift
find "$location" "$@"

No. My real example use getopt.

  Then why don't you post that?

If I have each option in a separate argument, I need to know all the
possible arguments to find, which is not a viable route.

  Are you trying to parse arguments that you should let find take care
  of?

--
   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]