|
|
Subscribe / Log in / New account

Debian's which hunt

Debian's which hunt

Posted Oct 29, 2021 6:24 UTC (Fri) by weberm (guest, #131630)
In reply to: Debian's which hunt by marcH
Parent article: Debian's which hunt

Pretty useless, isn't it?

$ which type
$ type type
type is a shell builtin
$ type -p type
$
# yes, its exit status tells me type exists, but not where
$ type ls
ls is aliased to `ls --color=auto'
# I hate that alias with a passion but sometimes forget to remove it. Not the point. It ought to tell me where the expanded alias is pulling that 'ls' in.
$ which ls
/bin/ls
$ command -v ls
alias ls='ls --color=auto'
$ command -V ls
ls is aliased to `ls --color=auto'

Nothing scratches my back just like which does.


to post comments

Debian's which hunt

Posted Oct 29, 2021 13:59 UTC (Fri) by pj (subscriber, #4506) [Link] (2 responses)

$ type -a ls
ls is aliased to `ls -F --color=auto'
ls is /bin/ls

IMO, `type` seems to be the best-thought-out version of this tool, and should be made standard.

Debian's which hunt

Posted Oct 29, 2021 21:15 UTC (Fri) by weberm (guest, #131630) [Link] (1 responses)

I assume you're using bash? zsh?

$ type -a ls
mksh: whence: -a: unknown option

IMO which being an external tool actually comes in quite handy here. It has its drawbacks, but also its benefits.

Debian's which hunt

Posted Oct 29, 2021 21:29 UTC (Fri) by marcH (subscriber, #57642) [Link]

For scripts it may depend on what you're trying to achieve but in _interactive_ use you should always, always use the builtin provided by your particular shell. It's likely not portable but who cares: it's interactive use. There's no drawback and huge benefits.

Debian's which hunt

Posted Oct 29, 2021 16:28 UTC (Fri) by overfl0w (guest, #155055) [Link]

On the other hand on my system I have vim and nvim installed simultaneously. I also apparently have the following alias which I've forgotten about in .bashrc:
alias vim='nvim' in .bashrc

So when I execute the 'vim' command, actually 'nvim' is executed.

$ which vim
/usr/bin/vim
$ command -v vim
alias vim='nvim'

So in this particular case 'which' did not return the correct path. Perhaps this is due to the fact that 'vim' is a valid command. But if I executed 'vim', it would not execute the executable returned by 'which'. I found this by accident as I hadn't heard about 'command -v' before.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds