Lorenzo Viali <[EMAIL PROTECTED]> wrote:
>         eval "\"$CMDFILE\" $list"
>         because i need $CMDFILE to receive more than
> one argument; but what happens is that if in the
> script's option's arguments, there are substrings like
> $i, those variable are expanded

That will also happen within $CMDFILE, since that variable is expanded
before eval sees it.  You could prevent the secondary expansion within
$CMDFILE by escaping the "$":
  eval "\"\$CMDFILE\" $list"
But that won't help with $list.

Option 1: don't use eval.
  "$CMDFILE" $list
In this case, you'd probably also want to use "set -f" first to
disable filename expansion in the contents of $list (and "set +f"
afterwards to restore filename expansion).  $list will still be split
at whitespace to produce multiple arguments.  The only restriction is
that you can't produce an argument containing whitespace.

Option 2: quote before eval.
When adding an arguemnt to list, quote it first by passing it through
this sed command:
sed "
s/'/'\\\\''/g
1s/^/'/
\$s/\$/'/
"
This way, you can include arguments containing whitespace, or any
other special characters.  They'll be quoted, so eval will only remove
the quotes, without further expansion.


paul


_______________________________________________
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash

Reply via email to