为什么“历史”?当命令来自文件时,tcsh 中不输出任何内容?
当我们在 tcsh 中输入“history”时,我们可以看到历史命令列表,如下所示:
ubuntu:~> echo a
a
ubuntu:~> history
1 9:20 echo a
2 9:20 history
但是,如果我们将命令存储在文件“commands.txt”中,
echo a
history
通过以下方式将该文件的内容重定向到 tcsh
tcsh < commands.txt
并且我们可以 看到的只是:
a
为什么会发生这种情况?为什么 shell 提示符也不属于输出的一部分?
顺便说一句,它实际上适用于 bash,你只需要像这样打开 history 选项
set -o history
echo a
history
When we type "history" in tcsh, we can see a list of history commands, like this:
ubuntu:~> echo a
a
ubuntu:~> history
1 9:20 echo a
2 9:20 history
However, if we store in commands in a file "commands.txt"
echo a
history
And we redirect the content of this file into tcsh by
tcsh < commands.txt
What we can see is only:
a
Why does this happen? And why shell prompt isn't part of the output either?
BTW, it actually works for bash, you just need to turn on history option like this
set -o history
echo a
history
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,这可能不是为什么问题的完美答案。但至少它为您提供了一些信息,这些信息不在脚本中使用历史命令。
在
http://www.tldp.org/LDP/abs/html/special -chars.html
搜索“历史”你会发现:
在 http://tldp.org/LDP/abs/html/histcommands.html 您可以在页面末尾找到:
well this maybe not a perfect answer to the question why. but at least it gives you some info, that don't use history command in a script.
in
http://www.tldp.org/LDP/abs/html/special-chars.html
search "history" you find:
in http://tldp.org/LDP/abs/html/histcommands.html you can find at the end of the page:
history 命令是 tcsh 内置命令,因此其行为与普通命令不同。根据“Csh 编程被认为有害”的咆哮,第 2a 节说
我不确定这是否是一种合理的方式。并且脚本不会打印命令提示符。
The history command is a tcsh built-in so doesn't behave like a normal command. Per the "Csh Programming Considered Harmful" rant, section 2a says
And I am not sure its even a reasonable way. And scripts don't print the command prompts.