fc -e 的退出状态是错误的

fc -e 的退出状态是错误的

我正在尝试使用 Bash 的内置命令编辑和调用先前的命令fc,但不知何故,退出状态表明成功编辑失败,即使这是一个无操作。演示:

$ uname
Linux
$ fc -e vi
:q
uname
Linux
$ echo $?
1
$ # Would have expected 0 here: successful re-invocation

man bash

   fc [-e ename] [-lnr] [first] [last]
   fc -s [pat=rep] [cmd]
          [...]
          If  the  first  form  is  used,  the return value is 0 unless an
          invalid option is encountered or first or last  specify  history
          lines  out  of  range.  If the -e option is supplied, the return
          value is the value of the last command executed or failure if an
          error occurs with the temporary file of commands.  [...]

进一步挖掘它:

$ uname
Linux
$ fc -e true -1  # No-op editor, should succeed.
uname
Linux
$ echo $?
1
$ # Why does this recall, but fail?
$ fc -e false -1 # Editor fails, no command invocation and failure, fine.
$ echo $?
1
$ fc -e rm -1    # This removes the temporary file, should fail, too!?
$ echo $?
0
$ # But actually this is the only branch that causes fc to succeed?!

对我来说, 的退出状态fc很混乱:成功(或无操作)编辑应该导致成功(或调用命令的退出状态),并且临时文件的删除应该由失败指示,不是相反

我在 Ubuntu 14.04.4 LTS 上的 Bash 4.3.11(1)-release、Ubuntu 16.04 LTS 上的 Bash 4.3.42(1)-release 以及 CentOS 7 上的 Bash 4.2.46(1)-release 中看到了这一点。这是一个错误吗?

答案1

是的,这是一个错误。早在 2015 年 11 月就已经报告并修复了该问题:http://lists.gnu.org/archive/html/bug-bash/2015-11/msg00107.html

我没有注意到 Git 存储库中的修复,因为我只查看了master.显然,开发发生在devel;目前修复仅在其中。一旦它进入 Bash 版本,我将更新这个答案。

相关内容