脚本如何知道用户是否可以输入?
答
从人的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.
您可以检查连接的TTY用'-t'标志'['/'test'。 –
这太宽泛了吗? –
“bash脚本(或其他语言)”非常广泛。另外“无头之路”是非常广泛的,没有进一步的澄清。这就是说我认为答案(对于bash)非常简单。 –