“历史-p”有什么作用?

时间:2017-10-03 18:06:39

标签: shell posix

我正在编写一个shell作为学校项目。 在builtins中有一个“历史”命令和一些选项,比如'-c'用于清理或'-s'用于在历史记录中添加args。 其中一个选项是'-p',男人说:

  

-p在args上执行历史记录替换并显示结果           在标准输出上,不将结果存储在历史列表中。

我真的不明白这个选项的作用。当我尝试它时,它会显示args并且不做任何其他事情。

有人知道吗?

1 个答案:

答案 0 :(得分:1)

  

-p对args执行历史记录替换并在标准输出上显示结果,而不将结果存储在历史记录列表中。

这是一个例子,它说明了它实际上做了什么

# clear history
$ history -c

# call date - this will be saved in history
$ date
Tue Oct  3 23:47:24 IST 2017

# call call - this also will be saved in history
$ cal
    October 2017      
Su Mo Tu We Th Fr Sa  
 1  2  3  4  5  6  7  
 8  9 10 11 12 13 14  
15 16 17 18 19 20 21  
22 23 24 25 26 27 28  
29 30 31              

# see what all saved so far
$ history
  996  date
  997  cal
  998  history

# see this prints string on stdout, but doesn't save in history
$ history -p "This is test string which is not stored in history"
This is test string which is not stored in history

#  as you can see history -p "....." is missing
$ history
  996  date
  997  cal
  998  history
相关问题