2012-02-06 36 views
1

当我们键入tcsh的“历史”,我们可以看到历史命令列表,像这样:当命令来自文件时,为什么'历史'不会在tcsh中输出任何内容?

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,你只需要这也许不是一个完美的答案打开历史选择这样

set -o history 
echo a 
history 

回答

0

很好的问题为什么。但至少它会给你一些信息,不要在脚本中使用history命令。

http://www.tldp.org/LDP/abs/html/special-chars.html 搜索 “历史”

你会发现:

注意,在脚本中,历史机制被禁用。

http://tldp.org/LDP/abs/html/histcommands.html,你可以找到在页面的末尾:

Unfortunately, the Bash history tools find no use in scripting. 

#!/bin/bash 
# history.sh 
# A (vain) attempt to use the 'history' command in a script. 

history      # No output. 

var=$(history); echo "$var" # $var is empty. 

# History commands disabled within a script. 

bash$ ./history.sh (no output) 
+0

我认为它实际上适用于bash,请参阅我的编辑。 – ablmf 2012-02-06 17:19:56

0

历史命令是内置所以不会表现得像一个正常的命令tcsh的。每咆哮了“是有害的Csh的编程”,部分2a说

你不能把[内建]一起在许多合情合理的方式。

而且我不知道它甚至合理方式。而脚本不会打印命令提示符。

相关问题