bug-bash
[Top][All Lists]
Advanced

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

Re: escaping arithmetic during evaluation


From: Paul Jarc
Subject: Re: escaping arithmetic during evaluation
Date: Thu, 07 Feb 2002 16:30:54 -0500
User-agent: Gnus/5.090006 (Oort Gnus v0.06) Emacs/20.7 (i386-redhat-linux-gnu)

"Matt P." <address@hidden> wrote:
> assignment: eval "${NAME}_bday="'"$BDAY"'
> evaluation:   eval 'echo "$'"${NAME}"'_bday"'
>
> This solution works most cases, except when NAME contains a special
> character, eg -, as in john-doe.
>
> I have tried a couple of solutions with a \ to escape the -, but I was
> unsuccessful.

You'll have to remove those characters, possibly replacing them with
underscores:
NAME="${NAME//[!A-Za-z0-9_]/_}"
Note that this will transform all of "foo bar", "foo.bar", and
"foo%bar" (among other) into the same "foo_bar", so you won't be able
to store different bdays for all of them using this method.  What you
really want are something like hash tables, but bash doesn't provide
those.


paul



reply via email to

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