工作需要,最近阅读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 */
评论
暂无评论~~