脚本如何知道用户是否可以输入?
How can a script know whether a user can input or not?
有没有一种方法 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.
有没有一种方法 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.