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說

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

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

相關問題