bash历史命令的转义破折号



在我的 Ubuntu 系统上,我想使用 bash history 命令来记住一些命令,但是当我输入命令时:

history -s "-t tag_name"

bash 报告错误:

bash: history: -t: invalid option
history: usage: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]

似乎-s选项的参数不能以破折号开头,因为当我输入类似的东西时

history -s "echo test"

它工作正常。

如何创造历史以记住以破折号开头的命令?(不添加前导空格)

你可以向history发出信号,表明你已经完成了传递参数,所以它不会尝试计算-t,如下所示:

history -s -- "-t tag_name"

最新更新