2008-02-06 16:16:49     Output of "which" is confusing for built-in commands

Document created by Aaronwu Employee on Sep 17, 2013
Version 1Show Document
  • View in full screen mode

2008-02-06 16:16:49     Output of "which" is confusing for built-in commands

Steve Strobel (UNITED STATES)

Message: 50773    It seems to me that BusyBox's implementation of which would be less confusing if it indicated when one of the built-in commands would take precedence over the commands in the path.  For example, I made a script called passwd that runs /bin/passwd, then copies /etc/passwd to another location.  I changed the path so the directory containing the script preceded /bin, and expected that it would be used whenever I typed "passwd" at the shell prompt.  It wasn't, even though "which passwd" indicated that it would be.  I then discovered that my script wouldn't be executed even if I deleted /bin/passwd.  I finally figured out that BusyBox was using its internal implementation of passwd.  It would have been much less confusing for me if the output of "which" had been "/bin/busybox".

 

Would a patch for such a change be welcome, or is there a good reason for keeping it as it is?  Thanks for any feedback.

 

Steve

QuoteReplyEditDelete

 

 

2008-02-06 16:28:27     Re: Output of "which" is confusing for built-in commands

Mike Frysinger (UNITED STATES)

Message: 50775    such a change wouldnt be acceptable.  which does exactly one thing: search $PATH for the requested program.

 

if you dont like the internal searching method of busybox, you can just disable it in the busybox configuration menu.

QuoteReplyEditDelete

 

 

2008-02-06 17:13:31     Re: Output of "which" is confusing for built-in commands

Steve Strobel (UNITED STATES)

Message: 50776    It isn't the internal searching method that confused me as much as the fact that I have always thought that the PURPOSE        of "which" was to indicate which implementation of a command would be used.  I understand that the IMPLEMENTATION has traditionally been to search the path.  In my opinion, that is just a means to achieve the purpose.  I will just have to adjust my expectations.  Thanks for the response.

 

Steve

QuoteReplyEditDelete

 

 

2008-02-06 17:32:59     Re: Output of "which" is confusing for built-in commands

Mike Frysinger (UNITED STATES)

Message: 50777    it's a logical break between the shell environment.  the internal searching of applets is a feature of the busybox shells.  you could say the same thing along the lines of shell functions overriding the PATH:

$ which stty

/bin/stty

$ stty() { echo moo; }

$ which stty

/bin/stty

 

you also would get inconsistent behavior if you used different which implementations.  only the which provided by busybox would be able to know about the internal searching the busybox shells are utilizing.  if you were to build the normal which package, that would exhibit the standard behavior of only searching PATH.

Attachments

    Outcomes