Hi elbrus!

On Sun, 10 Oct 2021 at 20:52:51 +0200, Paul Gevers wrote:
> Thanks for the report. I had committed nearly the same change locally.
> Can you elaborate why you removed some "2>&1" strings on top of that?

AFAIK with some `which` implementations one wants to silence the
standard error to avoid “foobar is not found” error messages, but per
current POSIX specs <https://pubs.opengroup.org/onlinepubs/9699919799/>
that's not needed for `command -v`:

  -v
    Write a string to standard output that indicates the pathname or
    command that will be used by the shell, in the current shell
    execution environment (see Shell Execution Environment), to invoke
    command_name, but do not invoke command_name.
    […]
        Otherwise, no output shall be written and the exit status shall
        reflect that the name was not found.

AFAICT the debianutils maintainer also suggest to use `command -v foobar
>/dev/null` as replacement for `which foobar >/dev/null [2>&1]`.  Its
5.3-1 NEWS entry reads:

  * The 'which' utility will be removed in the future.  Shell scripts
    often use it to check whether a command is available.  A more
    standard way to do this is with 'command -v'; for example:
      if command -v update-icon-caches >/dev/null; then
        update-icon-caches /usr/share/icons/...
      fi
    '2>/dev/null' is unnecessary when using 'command': POSIX says "no
    output shall be written" if the command isn't found.  It's also
    unnecessary for the debianutils version of 'which', and hides the
    deprecation warning.

Cheers
-- 
Guilhem.

Attachment: signature.asc
Description: PGP signature

Reply via email to