Timeline for Why not use "which"? What to use then?
Current License: CC BY-SA 4.0
12 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 7 at 4:19 | history | edited | Martin Kealey | CC BY-SA 4.0 | added 119 characters in body |
| Dec 23, 2024 at 4:26 | comment | added | dave_thompson_085 | Gack! You're right -- I first started thinking about the direct-use case, then realized you were using 'command', couldn't remember if it is special and looked up, but forgot to finish the thought that it is still an execution environment. Sorry :-( | |
| Dec 9, 2024 at 10:21 | comment | added | Martin Kealey | Sorry, the link to POSIX §2.9.1 in the previous comment should be pubs.opengroup.org/onlinepubs/9799919799/utilities/… | |
| Dec 9, 2024 at 10:11 | comment | added | Martin Kealey | OK, now I check [pubs.opengroup.org/onlinepubs/9799919799/utilities/… §2.9.1). So command is neither a special built-in nor a function, which means that the prefix assignment has exactly the scope I had assumed all along. (command itself is an intrinsic utility, meaning that the shell always invokes the built-in version, regardless of the current PATH.) | |
| Dec 9, 2024 at 9:56 | comment | added | Martin Kealey | @dave_thompson_085 I would have expected that a prefix assignment would be in the environment seen by command, so when the inner command is invoked, it's used to search for it. It seems to work that way in all the shells I've tested. However you do raise a valid concern about command not being a special built-in; this leaves it implementation defined as to whether the assignment is unwound when the command finishes. That said, I've not encountered an implementation that didn't unwind prefix assignments since about 1990. I will adjust the answer soon. | |
| Dec 8, 2024 at 3:31 | comment | added | dave_thompson_085 | PATH=$OTHERPATH command something ... doesn't change the lookup of something in shell's pre-existing PATH; it only changes the environment passed down to whatever is found standardly (if anything). (command is a builtin but not a special builtin.) | |
| Dec 7, 2024 at 14:33 | history | edited | Martin Kealey | CC BY-SA 4.0 | mention burnthewhich |
| Mar 4, 2024 at 2:03 | comment | added | Martin Kealey | @Seamus I reiterate this point: before one asks "how do I get the path to a command", it is more appropriate to step back, and ask yourself why do I need the path in this case, and is there a simpler design that means I don't need to know the path at all? | |
| Mar 4, 2024 at 1:55 | comment | added | Martin Kealey | @Seamus that depends; how and why are you using which? Is your use-case covered by any of the scenarios that I've mentioned above? | |
| Mar 2, 2024 at 23:26 | comment | added | Seamus | Do you feel that whereis is any "better" than which? | |
| Sep 10, 2022 at 0:58 | history | edited | Martin Kealey | CC BY-SA 4.0 | correct spelling "Stéphane" |
| Aug 17, 2022 at 4:48 | history | answered | Martin Kealey | CC BY-SA 4.0 |