Stay Hungry.Stay Foolish.
bash源码阅读笔记

工作需要,最近阅读bash源码, 使用的版本(version 4.3.0(3)-release)

bashhist.c 中有个bash_history_disable的函数,作用是使得执行的命令不记录到history文件中, 在bash 使用-c执行单条命令的时候有被调用, run_one_command->parse_and_execute (savestring (command), “-c”, SEVAL_NOHIST)), 第三个参数的SEVAL_NOHIST就是disable history, 关键代码如下

bashhist.c
277 void
278 bash_history_disable ()
279 {
280   remember_on_history = 0;
281 #if defined (BANG_HISTORY)
282   history_expansion_inhibited = 1;
283 #endif
284 }

./builtins/evalstring.c
203 #if defined (HISTORY)
204   if (flags & SEVAL_NOHIST)
205     bash_history_disable ();
206 #  if defined (BANG_HISTORY)
207   if (flags & SEVAL_NOHISTEXP)
208     history_expansion_inhibited = 1;
209 #  endif /* BANG_HISTORY */
210 #endif /* HISTORY */

问题

  • 为了避免奇奇怪怪的各种bug,建议使用官方镜像的二进制源码包基础上进行修改。
  • GNU bash, version 4.2.46(2)-release 括号里面的2代表./configure 第几次执行make。
自由转载-非商用-非衍生-保持署名(创意共享3.0许可证
评论

暂无评论~~