[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: no parameter expansion and no special meaning to control operator
From: |
Paul Jarc |
Subject: |
Re: no parameter expansion and no special meaning to control operator |
Date: |
Tue, 26 Sep 2006 20:55:06 -0400 |
User-agent: |
Gnus/5.110003 (No Gnus v0.3) Emacs/21.4 (gnu/linux) |
Lorenzo Viali <aesiko99@yahoo.com> 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