脳内コアダンプ
Saturday | May 25, 2013
標準入力のコンテキスト (コンソールなのか、パイプに繋がっているのか) を見て振る舞いを変えたい場合は、tty コマンドを使うと判定できます。#!/bin/shif tty -s; then echo "Terminal"else echo "Pipe"fi実行結果:% ./test.sh Terminal% echo foo | ./test.sh Pipe
#!/bin/shif tty -s; then echo "Terminal"else echo "Pipe"fi
% ./test.sh Terminal% echo foo | ./test.sh Pipe