bug-bash
[Top][All Lists]
Advanced

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

Re: a patch to fix sh_stat on SunOS


From: Chet Ramey
Subject: Re: a patch to fix sh_stat on SunOS
Date: Sun, 21 Aug 2016 15:04:07 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

On 8/20/16 9:31 PM, Dmitry Goncharov wrote:
> On Thu, Aug 11, 2016 at 07:52:51AM -0400, Chet Ramey wrote:
>> On 8/10/16 5:38 PM, Dmitry Goncharov wrote:
>>
>>>>> does "If any file argument to one of the primaries is of the form
>>>
>>>>> /dev/fd/n, then file descriptor n is checked.".
>>>
>>>
>>>> It seems like a documentation error.
>>>
>>> What should the man page say instead?
>>
>> Probably something close to what the current text about using /dev/fd in
>> redirections says, maybe:
> 
> Do you mean current text in process substitution?
> 
> The current text in redirection says
> "/dev/fd/fd
>     If fd is a valid integer, file descriptor fd is duplicated."

The current text in redirection says:

Bash handles several filenames specially when they are used in redirec-
       tions, as described in the following table.  If the operating system on
       which bash is running provides these special files, bash will use them;
       otherwise it will emulate them internally with the  behavior  described
       below.

The text for conditional expressions should say something similar.

> 
> There is asymmetry
>> /dev/fd/6 redirects to fd 6, while
> test -p /dev/fd/6 tests file "/dev/fd/6".

No.  If the OS provides /dev/fd and bash can detect it at build time,
process substitution, redirection, and conditional expressions will all
simply use the files the OS provides.  There is no asymmetry.


>> \fBBash\fP handles filenames of the form \fI/dev/fd\fP specially when they
>> are used as arguments to unary operators.
>> If the operating system on which \fBbash\fP is running provides these
>> special files, bash will use them; otherwise if
>> any \fIfile\fP argument to one of the primaries is of the form
>> \fI/dev/fd/n\fP, then file descriptor \fIn\fP is checked.
> 
> With this new contract how can the user write portable bash code which tests 
> if
> a fd refers to a pipe?

It's hard to say, given the existence of multiple incompatible
implementations of /dev/fd.  It looks like SunOS is the oddball here,
but there might be other implementations that don't do the same thing
with stat(2).

But why should bash override the semantics that an OS provides for
/dev/fd, resulting in differing behavior between the shell and other
utilities with the same pathname argument?

-- 
``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]