if (-t *STDIN) { # stdin is connected } else { # stdin is not connected } 我通常与-t *STDOUT一起使用,以查找我是从交互式shell还是从cron运行,以便启用更多输出。