Re: Multi-line, double quoted string triggers history expansion on subsequent single-quoted commands it gets piped to

2016-06-15 Thread Chet Ramey
On 6/14/16 8:52 AM, Néstor Tejero wrote:

> When printing a multi-line string and piping to another command that uses
> single-quotes, Bash tries to perform history expansion:
> 
> echo "9
>> 10
>> 9
>> 11" | awk '!seen[$0]++'
> bash: !seen[$0]++': event not found

History expansion is explicitly line-oriented.  It doesn't know about shell
state, especially shell quoting state, that spans lines. It does know about
vaguely shell-like quoting that's common across a large set of Unix
utilities -- since the history and readline libraries are used outside the
shell --  and that a double quote introduces a quoted string in which
single quotes are not significant and don't inhibit history expansion.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: Global variable modification by nameref chain

2016-06-15 Thread Chet Ramey
On 6/14/16 12:16 PM, Dan Douglas wrote:
> On Sun, Jun 12, 2016 at 8:33 PM, Chet Ramey  wrote:
>> 3. Honor the assignment and delete the nameref variable, creating a new
>>one, like bash-4.3:
>>
>> $ ../bash-4.3-patched/bash ./x1
>> declare -n a="b"
>> declare -n b="a[1]"
>> declare -a a='([1]="foo")'
>> declare -n b="a[1]"
> 
> I kind of like this option because it's consistent with `typeset -n`
> meaning "operate directly on the ref variable", and declare together
> with assignment meaning "redefine the variable" in most cases. I'm not
> so sure a warning is needed since replacing the variable with a new
> definition would be the usual thing to do with any other attributes,
> and the identifier literals used within one scope should be under
> control.

OK, just to play devil's advocate: why discard the existing value, since
any attribute other than nameref would result in it being preserved as
index 0?

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/