On 2014-01-28, at 06:17, Guido Berhoerster wrote:

> * Марк Коренберг <[email protected]> [2014-01-28 13:16]:
>> $ dpkg -l | fgrep dash
>> ii  dash                                   0.5.7-2ubuntu2
>>                POSIX-compliant shell
>> 
>> $ exec 9<no_such_file && echo TEST
>> dash: 1: cannot open no_such_file: No such file
>> 
>> $ exec 9<no_such_file || echo TEST
>> dash: 2: cannot open no_such_file: No such file
>> 
>> So, I cannot test this operation without using $?
> 
> No, exec is a special built in and POSIX specifies that
> ...if a redirection error occurs (see Consequences of Shell
> Errors), the shell shall exit with a value in the range 1-125
> 
> dash correctly exits with exit status of 2 as it should. ksh93,
> mksh, and pdksh do the same.
>  
My approach, which is often suitable, is such as:

    (   exec 9<some_file || exit $?
            ...
        commands using descriptor 9
            ...
    )

In almost all noninteractive shells I've tried, this
exits with error status either either directly on
failure of the redirection or because of the exit
command.  It's hard, then, to report the error
properly.  Some particularly perverse shells skip the
remainder of the command line upon failure of a prior
command.

-- gil

--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to