问题描述
为什么在子shell中运行bash history
内置函数的速度要慢56倍?
(我的历史记录中有22k行。也许这很重要吗?)
$ time history > /dev/null
real 0m0.064s
user 0m0.049s
sys 0m0.015s
$ # in a subshell it runs 56x slower:
$ time (history > /dev/null)
real 0m4.780s
user 0m2.558s
sys 0m2.215s
$ # trying "date" instead to show "time" isn't the issue:
$ date; history > /dev/null; date
Wed Oct 21 21:50:51 PDT 2020
Wed Oct 21 21:50:51 PDT 2020
$ date; (history > /dev/null); date
Wed Oct 21 21:50:51 PDT 2020
Wed Oct 21 21:50:56 PDT 2020
$ # each command in a pipeline is executed in a subshell (bash(1))
$ date; history | tail -1 > /dev/null; date
Wed Oct 21 21:50:56 PDT 2020
Wed Oct 21 21:51:01 PDT 2020
$ history|wc -l
22267
$ bash --version
GNU bash,version 4.4.12(1)-release (x86_64-apple-darwin15.6.0)
(macOS Mojave 10.14.6)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)