bug-bash
[Top][All Lists]
Advanced

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

Re: consistency probs var & function re-use


From: Chet Ramey
Subject: Re: consistency probs var & function re-use
Date: Sun, 11 Jun 2017 18:06:29 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.1.1

On 6/11/17 5:57 PM, L A Walsh wrote:
> 
> 
> Chris F.A. Johnson wrote:
>> On Fri, 9 Jun 2017, L A Walsh wrote:
>>> ----
>>>   First problem: If you are assigning a string to a variable,
>>> you need to put quotes around the string.
>>
>>    You don't need to quote it unless it contains literal whitespace.
> ---
>    Not true if you want to reproduce the string as output by
> "declare".  Since declare doesn't output the literal value in a
> variable, but an expanded one, you need to put quotes around any
> var that you intend to expand with 'declare'.
> 
> Greg's example:
> 
>   imadev:~$ x=$'foo\nbar'
>   imadev:~$ declare -p x
>   declare -- x="foo
>   bar"
> 
> Shows that "declare" isn't quoting its output such that it can be used for
> assignment to a var, or as 'read' input.

You are misunderstanding what that is supposed to do, or ignoring it.
`declare -p' quotes its output in a way that allows it to be reused as
shell input. Executing the output of `declare -p' will recreate the
variable with an identical value.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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