ksh errexit 条件执行
ksh errexit on conditional execution
考虑代码:
set -ex
for a in 1 2 3; do
[ $a == 1 ] || false
done
预期输出为:
+ [ 1 == 1 ]
+ [ 2 == 1 ]
+ false
然而我得到:
+ [ 1 == 1 ]
+ [ 2 == 1 ]
+ false
+ [ 3 == 1 ]
+ false
出于某种原因,ksh 决定在第二次迭代 false
后不退出。
运行 这个脚本通过 bash 提供了预期的结果。
有趣的是,通过将代码更改为:
,我可以说服 ksh 提供预期的结果
set -ex
for a in 1 2 3; do
[ $a == 1 ] || false
true
done
从表面上看,我所做的只是添加一个 true
命令,该命令实际上什么都不做。
我的 ksh 版本(OpenBSD 6.0 上的默认版本)是:@(#)PD KSH v5.2.14 99/07/13.2
在决定将其报告为错误之前,我想确保没有遗漏任何东西。
我不会把它作为错误提交,让我们现在看看一些历史。
目前存在Korn
shell个版本是
- 如果输出看起来像版本
JM 93u 2011-02-08
,那么你有
ksh93
。
- 如果输出看起来像
@(#)PD KSH v5.2.14 99/07/13.2
,那么你
有 pdksh (Public Domain Korn Shell)
.
- 如果输出看起来像
@(#)MIRBSD KSH R49 2014/01/11
,那么你
有 mksh (MirBSD Korn Shell)
.
您的 ksh
版本属于第二类,据此消息来源称,
pdksh is the public domain Korn shell, a clone of the Korn Shell. It has most of the ksh88 features, and almost none of the ksh93 features. The last version, pdksh 5.2.14 from 1999 July 13, still has several bugs. Systems like Debian, OpenBSD and PLD now apply several patches to pdksh
.
难怪你的 ksh 版本已经过时了,我试着为你的 shell 版本进行了适当的维护 change-log 并将其与您报告的问题的补丁发布版本,我找不到它,难怪它不再维护。
但我的 MacOSX
、sh (AT&T Research) 93u+ 2012-08-01
、运行 的最新 ksh93
版本也是如此完全符合您的预期,
+ [ 1 '==' 1 ]
+ [ 2 '==' 1 ]
+ false
建议升级您的 ksh 版本以进行进一步研究,因为您的版本已经过时并且 error-prone,或者如果您仍然想报告,假设是否有对此的积极支持,您可以联系本 pdksh(1) - Linux man page.
的 Bugs 部分中提到的 mailing-list
我相信这已在 -current 中修复。
http://marc.info/?t=148076436600001
http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/bin/ksh/exec.c?sortby=date&f=h#rev1.65
考虑代码:
set -ex
for a in 1 2 3; do
[ $a == 1 ] || false
done
预期输出为:
+ [ 1 == 1 ]
+ [ 2 == 1 ]
+ false
然而我得到:
+ [ 1 == 1 ]
+ [ 2 == 1 ]
+ false
+ [ 3 == 1 ]
+ false
出于某种原因,ksh 决定在第二次迭代 false
后不退出。
运行 这个脚本通过 bash 提供了预期的结果。
有趣的是,通过将代码更改为:
,我可以说服 ksh 提供预期的结果set -ex
for a in 1 2 3; do
[ $a == 1 ] || false
true
done
从表面上看,我所做的只是添加一个 true
命令,该命令实际上什么都不做。
我的 ksh 版本(OpenBSD 6.0 上的默认版本)是:@(#)PD KSH v5.2.14 99/07/13.2
在决定将其报告为错误之前,我想确保没有遗漏任何东西。
我不会把它作为错误提交,让我们现在看看一些历史。
目前存在Korn
shell个版本是
- 如果输出看起来像版本
JM 93u 2011-02-08
,那么你有ksh93
。 - 如果输出看起来像
@(#)PD KSH v5.2.14 99/07/13.2
,那么你 有pdksh (Public Domain Korn Shell)
. - 如果输出看起来像
@(#)MIRBSD KSH R49 2014/01/11
,那么你 有mksh (MirBSD Korn Shell)
.
您的 ksh
版本属于第二类,据此消息来源称,
pdksh is the public domain Korn shell, a clone of the Korn Shell. It has most of the ksh88 features, and almost none of the ksh93 features. The last version, pdksh 5.2.14 from 1999 July 13, still has several bugs. Systems like Debian, OpenBSD and PLD now apply several patches to
pdksh
.
难怪你的 ksh 版本已经过时了,我试着为你的 shell 版本进行了适当的维护 change-log 并将其与您报告的问题的补丁发布版本,我找不到它,难怪它不再维护。
但我的 MacOSX
、sh (AT&T Research) 93u+ 2012-08-01
、运行 的最新 ksh93
版本也是如此完全符合您的预期,
+ [ 1 '==' 1 ]
+ [ 2 '==' 1 ]
+ false
建议升级您的 ksh 版本以进行进一步研究,因为您的版本已经过时并且 error-prone,或者如果您仍然想报告,假设是否有对此的积极支持,您可以联系本 pdksh(1) - Linux man page.
的 Bugs 部分中提到的 mailing-list我相信这已在 -current 中修复。
http://marc.info/?t=148076436600001
http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/bin/ksh/exec.c?sortby=date&f=h#rev1.65