shell - "history -p"有什么作用?

标签 shell posix

我正在编写一个 shell 作为学校项目。
在内置函数中有一个“历史”命令和一些选项,例如用于清理的“-c”或用于在历史上添加参数的“-s”。
选项之一是“-p”,男人说:

-p Perform history substitution on the args and display the result on the standard output, without storing the results in the history list.



我真的不明白这个选项的作用。当我尝试它时,它会显示参数并且什么也不做。

有人知道吗?

最佳答案

-p Perform history substitution on the args and display the result on the standard output, without storing the results in the history list.



这是示例,它说明了它的实际作用
# 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

关于shell - "history -p"有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46550780/

相关文章:

bash - 是否有更一致的方式来声明 Bash 变量和函数?

linux - sed如何在第一行末尾添加带竖线的变量

posix - POSIX 有更改日志吗?

macos - 如何在 OSX 上迭代所有挂载的文件系统

c++ - POSIX 线程中的唯一值

c - fork() 和 pipe() 的小问题

shell - sed 命令在每个操作系统之间的行为差​​异及其含义

linux - 循环 bash 脚本

python - 从命令行运行 python 脚本时导入语句不起作用

ios - 获取 WKWebView 的当前内存使用情况?