/usr/bin/which




















Locally defined aliases aren't inherited when running a shell script unless you source it with. That's why you'll notice csh scripts usually start with! POSIX shells users have command -v. See the answers for why. That assumes ls is indeed a command found on the file system not a builtin of your shell, or function of alias.

The point here is that which is a broken heritage from csh. Show 5 more comments. Active Oldest Votes. Use Cases There's a distinction between looking for that information as part of a script or interactively at the shell prompt. Most of the available tools as is often the case have been designed to be used interactively.

History A bit of history first. The fish shell has a type command implemented as a function. Implementations There are dozens of implementations of a which command on various Unices with different syntax and behaviour.

There are a few issues though: It is not possible to know the path of the executable without executing it. All the type , which , command -v There are some circumstances where you may need to take that into account. Keep in mind for instance that the list of builtins varies with the shell implementation for instance, mount is sometimes builtin for busybox sh , and for instance bash can get functions from the environment. So the path you obtain at the time you run command -v will no longer be valid after you cd somewhere else.

Find commands only in some shells A case where it might make sense to use which is if you want to know the path of a command, ignoring potential shell builtins or functions in bash , csh not tcsh , dash , or Bourne shell scripts, that is shells that don't have whence -p like ksh or zsh , command -ev like yash , whatis -p rc , akanga or a builtin which like tcsh or zsh on systems where which is available and is not the csh script.

Improve this answer. Joe, which is a csh script on many commercial Unices. The reason is historical, that's why I gave the history, so people understand where it came from, why people got used to using it and why actually there's no reason you should be using it. And yes, some people use t csh. After reading this post, I have found a lot of context for the answer, but not the answer itself.

Where in this post does it actually say why not to use which , as opposed to things you might be trying to use which to do, the history of which , implementations of which , other commands to do related tasks, or reasons to actually use which? Why are the other commands better? What do they do differently from which? How do they avoid its pitfalls? This answer actually spends more words on the problems with the alternatives than the problems with which.

FreeBSD sh also based on ash has the same bug. Show 10 more comments. CentOS 6. Debian 7. Community Bot 1. In your 1st example, even if ls is a function it is using ls from PATH. I don't see "Why not use which" No, no, no.

I know already that my ls is a function. However, what about users? Ben Hutchings. This was csh-specific and I think it later became built-into csh. FreeBSD 2. This was written in Perl and then rewritten in C a few years later. Debian's implementation started out in or as a shell script calling 'type', and remains a shell script. This is written in C. So 'which' has a very long history in csh, which was the default interactive shell in many versions of Unix.

Its availability to other shells dates back to the 90s at least but is not portable due to there being multiple very different implementations. Geert Stappers. Make such take over possible. Colin Watson. Aug 19, , AM Aug RumeshSudhaharan you should not do that, because it's managed by the package management. If any other package also wants to use that path, it will overwrite your file. Files in packages can never overlap at least for official repositories , so you are more safe when installing in the local path.

Also, it's just for your own convenience and safety. In a local path you can't mess up the system in such a bad way and you can't accidentally replace a system binary. I like the explanation on the error page : Severity:Serious Certainty:Certain — cutrightjm.

Reza Nasirloo. FWIW, sbin has nothing to do with scripts. It stores binaries - even the links provided note that. Show 3 more comments.

System directories for binaries man hier hierarchy lists all the directories. What I know I don't know I'm contemplating taking some of my more complex bash scripts in Ask Ubuntu and setting them up with install scripts on github. Community Bot 1. I appreciate your effort, but , except the "What I know I don't know" part, you repeated gertvdijk's answer. But gertvdijk already mentioned the Filesystem Hierarchy Standard which man hier is an informationally insufficient excerpt of IMO.

See full activity log. To post a comment you must log in. Report a bug. This report contains Public information Edit Everyone can see this information. You are not directly subscribed to this bug's notifications. Other bug subscribers Subscribe someone else. Bug attachments Dependencies. Unassigned Edit. You need to log in to change this bug's status. Affecting: debianutils Ubuntu. Assigned to. Georg georg-lippold wrote on :.



0コメント

  • 1000 / 1000