[PATCH] which code cleanup
Tito
farmatito at tiscali.it
Fri May 2 19:31:21 UTC 2014
On Friday 02 May 2014 15:42:40 you wrote:
> Tito wrote:
>
> > That's it about PATCH 1.
> > There is still PATCH 2....
> Your patch searches in PATH for dir/file if dir/file is not executable.
> The normal behavior is to not search PATH if the argument contains a '/'.
Fixed. Thanks!
> If you rewrite "which" anyway, you could also change the following points:
> - Remove default PATH, saves some bytes
It mimics the behavior of debianutils which that being a script
sets PATH (from profile?) in its subshell:
debian:~/Desktop/SourceCode/new_bb/busybox$ cp /usr/bin/which .
debian:~/Desktop/SourceCode/new_bb/busybox$ nano which (add echo $PATH)
debian:~/Desktop/SourceCode/new_bb/busybox$ unset PATH
debian:~/Desktop/SourceCode/new_bb/busybox$ echo $PATH
debian:~/Desktop/SourceCode/new_bb/busybox$ ./which pippo
PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
debian:~/Desktop/SourceCode/new_bb/busybox$ echo $PATH
> - Output message if not found (maybe if DESKTOP)
> - Return number of commands not found as per man page (Which returns the
> number of failed arguments, or -1 when no `programname´ was given)
WHICH(1) WHICH(1)
NAME
which - locate a command
SYNOPSIS
which [-a] filename ...
DESCRIPTION
which returns the pathnames of the files (or links) which would be executed in the current
environment, had its arguments been given as commands in a strictly POSIX-conformant shell.
It does this by searching the PATH for executable files matching the names of the arguments.
It does not follow symbolic links.
OPTIONS
-a print all matching pathnames of each argument
EXIT STATUS
0 if all specified commands are found and executable
1 if one or more specified commands is nonexistent or not executable
2 if an invalid option is specified
Debian 1 May 2009 WHICH(1)
debian:~$ which pippo pluto topolino
debian:~$ echo $?
1
> $ which -v
> GNU which v2.20, Copyright (C) 1999 - 2008 Carlo Wood.
> $ (unset PATH; /usr/bin/which -a sh bash; echo $?)
> /usr/bin/which: no sh in ((null))
> /usr/bin/which: no bash in ((null))
> 2
>
>
Attached v2 of which patch and a drop in which.c replacement file for
testing purposes.
Ciao,
Tito
-------------- next part --------------
A non-text attachment was scrubbed...
Name: which_v2.patch
Type: text/x-patch
Size: 2471 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20140502/02309f12/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: which.c
Type: text/x-csrc
Size: 1468 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20140502/02309f12/attachment.c>
More information about the busybox
mailing list