Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I just realized that my sysadmin has created a global alias for which:

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

The which manpage just says:

Stop processing options on the right if not on tty.

What does this mean?

share|improve this question

2 Answers 2

up vote 8 down vote accepted

Setup:

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

If you wanted the . version when run interactively, but the ~ version when redirected, you would could use this as an alias:

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

Demo:

# 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

All the options you specify after --tty-only are taken into account only when the output is a tty.

share|improve this answer
    
Nice! I did't realise which can do fancy things I always figured it for as dull a tool as there are. –  Bananguin Apr 24 '13 at 6:23
    
It is a dull tool on my Ubuntu 13.4 box, it only has the -a option –  Gerard Apr 24 '13 at 12:28
    
@Gerard: see Sukminder's answer. Debian-based systems don't have those features. There are workarounds in the bug linked. –  Mat Apr 24 '13 at 15:00

That would mean that if output for which does not refer to a terminal, then do not process --read-alias, --show-dot and --show-tilde.

Typically if to a pipe, ordinary file etc.

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

The options are not recognized under e.g. debian:

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.