2012-02-11 87 views
1

在bash中,可以使用如何檢查變量或命令是否來自bash或unix?

env 
printev 

打印環境(全局)變量,或者使用

set 

打印局部變量。 但是,如何知道這個變量是來自bash腳本環境,還是來自unix操作系統呢?

類似問題的命令,一個怎麼會知道

ls 
grep 
od 

等,是從Ubuntu OS或bash的環境?

+0

你的第一個問題沒有意義。變量是什麼意思是「來自unix [操作系統]」? – 2012-02-11 13:47:05

+0

哦!,所以沒有操作系統變量?對不起,如果我提出了一個愚蠢的錯誤問題...在Windows中,有一些系統變量,如路徑等... – athos 2012-02-11 13:57:50

+0

有環境變量(如路徑),但沒有區別的環境變量,由shell和一個被繼承的。 – 2012-02-11 14:07:37

回答

6

您可以使用內建的type

[[email protected] ~]$ type ps 
ps is /bin/ps 
[[email protected] ~]$ type type 
type is a shell builtin 
[[email protected] ~]$ type ls 
ls is aliased to `ls --color=auto' 
[[email protected] ~]$ type if 
if is a shell keyword 
+0

我想這些用於命令:「ps是/ bin/ps」表示這是「UNIX OS命令」; 「shell builtin」=>「bash環境命令」; 「shell關鍵字」=>「bash shell保留關鍵字」?那麼變量怎麼樣?當我運行「輸入$ PS1」時,它顯示「-bash:type:\ t \ s \ e [0; 34m \ w \ e [m \ $:not found」;當我運行「鍵入$ IFS」時,它什麼也沒有顯示...... – athos 2012-02-11 13:56:12

+0

@athos的確,'type'不能區分環境變量和shell屬性。 – cnicutar 2012-02-11 13:59:46

相關問題