Bug 24885

Summary: /bin/sh глючит
Product: Sisyphus Reporter: at <at>
Component: shAssignee: placeholder <placeholder>
Status: NEW --- QA Contact: qa-sisyphus
Severity: normal    
Priority: P3 CC: glebfm, ldv, placeholder, vvk
Version: unstable   
Hardware: all   
OS: Linux   

Description at@altlinux.org 2011-01-10 06:24:52 MSK
$ cat ./test.sh
#!/bin/sh -efu
echo a |
while read -r a; do
        rm /no/such/file
done
echo ok a
echo b |
        rm /no/such/file
echo ok b
$ ./test.sh
rm: cannot remove `/no/such/file': No such file or directory
ok a
rm: cannot remove `/no/such/file': No such file or directory
$

В первом случае errexit не сработал, во втором - сработал.  Мне так скрипты писать неудобно.  А то вроде скрипт отработал а потом смотришь там такой швах!
Comment 1 Alexey Gladkov 2011-01-10 10:59:32 MSK
$ sh -efu ./test.sh
rm: cannot remove `/no/such/file': No such file or directory
ok a
rm: cannot remove `/no/such/file': No such file or directory

$ dash -efu ./test.sh
rm: cannot remove `/no/such/file': No such file or directory

$ mksh -efu ./test.sh
rm: cannot remove `/no/such/file': No such file or directory
Comment 2 Dmitry V. Levin 2011-02-05 01:01:08 MSK
From bash-4.0/COMPAT:

42. Bash-4.0 changes the handling of the set -e option so that the shell exits
    if a pipeline fails (and not just if the last command in the failing
    pipeline is a simple command).  This is not as Posix specifies.  There is
    work underway to update this portion of the standard; the bash-4.0
    behavior attempts to capture the consensus at the time of release.
Comment 3 Dmitry V. Levin 2011-02-05 01:09:26 MSK
Я не буду бэкпортить это изменение в поведении bash.
Когда будем собирать более новый bash, тогда произойдет и это изменение.