Preben Randhol <firstname.lastname@example.org> [2002-09-21 10:55:48 +0200]: > Bob Proulx <email@example.com> wrote on 19/09/2002 (18:07) : > > quote format just to be explicit. And it makes cut-n-paste easier. > > > > which mozilla > > > > But instead of that old csh script 'which' I prefer newer commands > > such as 'command' or 'type'. (Yes I see that on debian which is > > now a bash script instead of a csh script. But this is not true > > everywhere.) > > > > type mozilla > > > > command -v mozilla > > Isn't it kind of stupid to suggest a bash only solution? Especially if > you want to use this in a script like: > > #!/bin/sh > BROWSER=`which mozilla` It pains me that you used that harsh language to describe my comment. I never said anything about bash only syntax. Anyone that said so was just caught up in the excitement of the moment! :-) Those are /bin/sh syntax, which I prefer better than anything that depends upon /bin/csh. I don't know why you thought that was bash only. [*] Those commands are defined by SUSv2. I am pleased that I can refer you to these pages for your edification. (And perhaps mine too in the case that I made a mistake here. I am only too well aware that the sword can cut both ways.) http://www.unix-systems.org/single_unix_specification_v2/xcu/type.html http://www.unix-systems.org/single_unix_specification_v2/xcu/command.html Repeat after me, "Standard is better than better." And then say, "Every programmer should strive to write portable code." But to do that one must learn about systems other than their home system. It is a challenge and very hard to accomplish fully. I have devoted many years to the task and know that I will never fully achieve the goal. The 'which' command does not have any standards behind it. Different systems implement it differently. As has been pointed out by others in this thread it is very troublesome to use portably across different operating systems. For example, on most operating systems it is implemented as a #!/bin/csh script which will read a user's individual ~/.cshrc file and be affected by the contents there! On the original BSD systems the which command was a #!/bin/csh script. It still is on most systems. I found it strange that on Debian it was a bash script! It trades one set of problems for another different set of problems. The man page on systems where this is a csh script contains these warnings reproduced here. WARNINGS which reports .cshrc aliases even when not invoked from csh. which cannot find csh built-in commands (e.g. jobs). which's information may be incorrect because it is unaware of any path or alias changes that have occurred in the current shell session. The POSIX shell is based upon the AT&T ksh. Both the posix shell and ksh define 'whence' instead of other things. As a precompiled builtin to those shells, which may be changed at compile time, aliases for type are provided where type='whence -v'. Normal ksh users have always learned to use 'whence' as the command to find things. Normal csh users have always learned 'which' as the command to find things. The old Bourne /bin/sh did neither. It really is getting hard to find a standard way of finding executable files! The 'whereis' command is yet different still. It does not look on _your_ path. It looks in the system provided path. This would include places like /usr/src, /usr/man, /usr/lib and other such places tht might not be on your path but where the 'whereis' command might be able to find the file you were looking for. It finds source code, man pages, and not just binaries. (I am pretty sure that at one time it would load up the path the system loaded up in /etc/rc but my memory is faded and I may be confusing it with another command.) I am almost ready to meantion the BSD fast find command since mentioning 'whereis' transitions to finding general files. We now know the BSD fast find as the 'locate' command. But I seriously take this thread off topic if I do that. :-) Bob Footnote [*]: 'type' works in all posix sh, ash, bash, zsh, I just checked. 'command' works everywhere but zsh but zsh does not claim to be a POSIX complaint shell, not suitable for /bin/sh so that is okay. It even works in csh, on other systems like hpux, I just checked. (HPUX probably improved the command for standards conformance. A standard csh, ha!) It did not work on csh on Debian, however, did not expect it to work and mentioned that specifically. I am sure that those would _not_ work on older, true Bourne shell /bin/sh systems, I said it was a newer syntax. Many people who used the older systems will have learned to avoid this on Bourne shells because of that.
Description: PGP signature