Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ユーザーに「読み取り」の入力を求めるbashスクリプトがあります。stdout または stderr が端末以外にパイプされている場合、このステップを抑制したいと思います。それは可能ですか?
コマンド test -t <filedescriptor no.> を使用して、ファイル記述子が tty (端末に接続されている) であるかどうかを確認できます。そうである場合は、ユーザーにプロンプトを表示できます。そうでない場合、出力はおそらくどこかにパイプまたはリダイレクトされます。
if test -t 1 ; then echo stdout is a tty fi