2016-04-26 80 views
0

bash腳本(或任何語言)可以確定它是否以無頭方式運行嗎?我想知道用戶是否可以輸入。如果可以的話,我會問他們一些事情。腳本如何知道用戶是否可以輸入?

+0

您可以檢查連接的TTY用'-t'標誌'['/'test'。 –

+0

這太寬泛了嗎? –

+0

「bash腳本(或其他語言)」非常廣泛。另外「無頭之路」是非常廣泛的,沒有進一步的澄清。這就是說我認爲答案(對於bash)非常簡單。 –

回答

0

人的bash

An interactive shell is one started without non-option arguments and without the -c option whose standard input and 
     error are both connected to terminals (as determined by isatty(3)), or one started with the -i option. PS1 is set and 
     $- includes i if bash is interactive, allowing a shell script or a startup file to test this state. 
相關問題