[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] bash variable interpolation
From: |
Chet Ramey |
Subject: |
Re: [Help-bash] bash variable interpolation |
Date: |
Thu, 19 Mar 2015 18:19:40 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 |
On 3/19/15 6:04 PM, Peng Yu wrote:
> Hi,
>
> I want to interpolate variable in a bash string variable. But the
> following code shows the spaces are not maintained. There is some
> built-in features in perl to do string interpolation. Does anyone know
> the best way to do string interpolation in bash? Thanks.
This seems much more complex than necessary. You're using eval, which is
going to require a second set of escaped quotes to account for the second
set of word expansions.
What's wrong with something like
str="$x $y $z"
and then using
echo "$str"?
Do you require the delayed evaluation?
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU address@hidden http://cnswww.cns.cwru.edu/~chet/