bug-bash
[Top][All Lists]
Advanced

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

Re: Documentation issue


From: Chet Ramey
Subject: Re: Documentation issue
Date: Thu, 26 Oct 2017 14:02:00 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.4.0

On 10/26/17 11:28 AM, Eli Barzilay wrote:

>> I'm not sure why this is a surprise. Pathname expansion (globbing) is
>> one of the word expansions performed before a simple command is
>> executed. The `unset' builtin is no different.
> 
> The last sentence is showing why it's a surprise: it is confusing since
> it easy to think that unset is special, similar to languages which have
> something like `delete foo[1]` where the thing that follows delete is an
> lvalue.

I understand. There are plenty of misconceptions out there. But the bash
documentation has never implied that `unset' is special in that way, and
it's not the man page's place to say everything the shell is not.

>>> The thing is that AFAICT, there is no mention of this pitfall in the
>>> man page...
>>
>> "The  unset  builtin  is  used to destroy arrays.  unset name[subscript]
>> destroys the array element at index subscript.  Negative subscripts  to
>> indexed  arrays are interpreted as described above.  Care must be taken
>> to avoid unwanted side effects caused  by  pathname  expansion."
> 
> 1. This is much more indirect than a simple "always quote array
>    references";

Because it's much more general than a blanket statement like that, and the
man page isn't the place for those statements. That's the job for a shell
programming guide, of which there are plenty.

> 
> 2. I completely missed it since it's not in the place which describes
>    unset.
> 
> (BTW, when I did dare for the first time to use unset on an array I did
> go through the unset description, and got a vague impression that it's
> kind of doing the special lvalue thing, so possibly the indirect warning
> would have been sufficient to slap me back into the bash reality.)

It's more of a general statement about arrays, though it appears in the
paragraph that discusses unset, so it's in the man page section on arrays.
You have to be careful about putting the same information in too many
different places -- the man page is big enough already.

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



reply via email to

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