[pacman-dev] [PATCH] scripts: replace test builtin [ with shell keywords [[ and ((

Isaac Good pacman at isaac.otherinbox.com
Tue Nov 10 16:07:10 EST 2009

On Tue, Nov 10, 2009 at 02:23:25PM -0600, Dan McGee wrote:
> On Tue, Nov 10, 2009 at 2:20 PM, Cedric Staniewski <cedric at gmx.ca> wrote:
> >
> > It might be enough, but I wonder, as well, why the -p option is used. I removed it in my patch since it is not needed when testing the return code, but maybe I missed something.
> dmcgee at galway ~/projects/pacman (gpg-more)
> $ type -p xdelta3; echo $?
> 1
> dmcgee at galway ~/projects/pacman (gpg-more)
> $ type xdelta3; echo $?
> -bash: type: xdelta3: not found
> 1
> Note that -p suppresses error messages that you may not want; it's
> output is only the return code.
> -Dan

The -p only suppresses error messages (STDERR) when it fails. On success it still emits the path to the file on disk (STDOUT).
If you want to do the test like this:
 $ if [ -n "$(type -p xdelta3)" ] ; then
then that is the desired behaviour. Output on success, nothing on failure. If you want to just use the return status, you still need to do something with the STDOUT.
 $ if type -p xdelta3 >/dev/null ; then
 $ if type xdelta3 >/dev/null 2>&1 ; then

More information about the pacman-dev mailing list