Path: utzoo!attcan!uunet!munnari.oz.au!uhccux!ames!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.unix.questions Subject: Re: How to get the pathname of the current executable? Message-ID: <12136@smoke.BRL.MIL> Date: 14 Feb 90 15:32:16 GMT References: <1610.25d028a3@wums.wustl.edu> <1990Feb7.211538.3894@iwarp.intel.com> <5378@buengc.BU.EDU> <1747@skye.ed.ac.uk> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 72 In article <1747@skye.ed.ac.uk> richard@aiai.UUCP (Richard Tobin) writes: >Different shells potentially interpret commands in completely different >ways. A command like which *has* to depend on your shell. It seems clear >to me that which should be built-in to csh and sh - that way it would >always be right. Well, without a precise definition of what it is that we expect "which" to do, the issue cannot be settled. My own view is that "which" and "every" should report ONLY on $PATH-based commands (assuming standard UNIX, i.e., not multiple mounts on /bin), and that "whatis" should be a builtin that produces a definition suitable for feeding back to the shell (unlike System V's "type" builtin). Here are some typical examples: $ echo $PATH /usr/lbin:/usr/5bin:/bin:/usr/bin:~/bin:/usr/ucb:. $ whatis which /usr/lbin/which $ whatis every /usr/lbin/every $ whatis whatis # 8th or 9th Edition UNIX or BRL Bourne shell builtin whatis $ whatis cd builtin cd $ whatis builtin # 8th or 9th Edition UNIX or BRL Bourne shell builtin builtin $ whatis l l () { ( set +u ; exec ls -bCF $* ) } $ whatis sh /usr/lbin/sh $ whatis xyzzy # xyzzy not found $ which which /usr/lbin/which $ which every /usr/lbin/every $ which whatis /usr/ucb/whatis $ which cd which: cd: not found $ which builtin which: builtin: not found $ which l which: l: not found $ which sh /usr/lbin/sh $ which xyzzy which: xyzzy: not found $ every which /usr/lbin/which /usr/ucb/which $ every every /usr/lbin/every $ every whatis /usr/ucb/whatis $ every cd every: cd: not found $ every builtin every: builtin: not found $ every l every: l: not found $ every xyzzy every: xyzzy: not found $ every sh /usr/lbin/sh /usr/5bin/sh /bin/sh (Actually, for interactive use I normally redefine "cd" and "which" using shell functions, but the example is clearer if I show the default behavior.)