[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Best way to suppress the error message in $(< nonexisten
From: |
Chet Ramey |
Subject: |
Re: [Help-bash] Best way to suppress the error message in $(< nonexistent_file) |
Date: |
Wed, 28 Nov 2018 08:41:09 -0800 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 |
On 11/28/18 7:56 AM, Peng Yu wrote:
>> $ echo >&-
>> -bash: echo: write error: Bad file descriptor
>>
>> So an application using this descriptor may eg. crash.
>
> I don't quite understand. Why this command does not cause any error?
>
> { x=$( <doesnotexist) ;} 2>&-
Because the error message is written while stderr is still closed. It's
not restored until the group command completes.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU address@hidden http://tiswww.cwru.edu/~chet/