脚本如何知道用户是否可以输入?

问题描述:

bash脚本(或任何语言)可以确定它是否以无头方式运行吗?我想知道用户是否可以输入。如果可以的话,我会问他们一些事情。脚本如何知道用户是否可以输入?

+0

您可以检查连接的TTY用'-t'标志'['/'test'。 –

+0

这太宽泛了吗? –

+0

“bash脚本(或其他语言)”非常广泛。另外“无头之路”是非常广泛的,没有进一步的澄清。这就是说我认为答案(对于bash)非常简单。 –

人的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.