web-dev-qa-db-ja.com

--tty-onlyオプションは何をしますか?

システム管理者がwhichのグローバルエイリアスを作成したことに気づきました。

alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

whichのマンページには次のように書かれています。

Ttyにない場合は、右側のオプションの処理を停止します。

これは何を意味するのでしょうか?

6
RSFalcon7

セットアップ:

$ /usr/bin/which --show-dot a
./a
$ /usr/bin/which --show-tilde a
~/a

インタラクティブに実行するときに.バージョンが必要であるが、リダイレクトされるときに~バージョンが必要な場合は、これをエイリアスとして使用できます。

/usr/bin/which --show-tilde --tty-only --show-dot

デモ:

# interactive / on a tty
$ /usr/bin/which --show-tilde --tty-only --show-dot a
./a
# not interactive / redirected to a file
$ /usr/bin/which --show-tilde --tty-only --show-dot a > output
$ cat output 
~/a

--tty-onlyの後に指定するすべてのオプションは、出力がttyの場合にのみ考慮されます。

8
Mat

つまり、whichの出力がnotが端末を参照している場合、次に、notprocess --read-alias--show-dotおよび--show-tilde

通常、パイプ、通常のファイルなどの場合。

which watch | foo # not a tty
which watch > foo # not a tty
which watch       # tty
which watch >&2   # tty

オプションは、例えばの下で認識されません。 debian

3
Runium