mainautogen - Support: sr #111041, Dependency on non-portable and...


sr #111041: Dependency on non-portable and unreliable "which" command

Submitter:  Eli Schwartz <eschwartz>
Submitted:  Wed 27 Mar 2024 03:21:33 AM UTC
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open Operating System:  None
* Mandatory Fields

Add a New Comment Rich Markup

Wed 27 Mar 2024 03:21:33 AM UTC, original submission:  

I noticed this when trying to build sharutils, which has libopts.m4 that ultimately comes from autogen.

  • QA Notice: command not found:
  • ./configure: 1: which: not found
  • ./configure: 1: which: not found

The code looks like this:

  [while :
      test -x "$POSIX_SHELL" && break
      POSIX_SHELL=`which bash`
      test -x "$POSIX_SHELL" && break
      POSIX_SHELL=`which dash`
      test -x "$POSIX_SHELL" && break
      test -x "$POSIX_SHELL" && break
      POSIX_SHELL=`/bin/sh -c '
          exec 2>/dev/null
          if ! true ; then exit 1 ; fi
          echo /bin/sh'`
      test -x "$POSIX_SHELL" && break
      ]AC_MSG_ERROR([cannot locate a working POSIX shell])[
           [define to a working POSIX compliant shell])

Unfortunately, the use of "which bash" to check whether a bash program exists fails when the "which" command doesn't exist. See e.g.

In general, you can and should use "command -v" for this. It was part of POSIX 2008. A simple "s/which/command -v/" suffices.

However since this is a macro collection for autoconf it seems more apropos to use AC_CHECK_PROG or AC_CHECK_PROGS instead...

Eli Schwartz <eschwartz>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by eschwartz (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.


    No changes have been made to this item

    Back to the top

    Powered by Savane 3.13-6ae7.
    Corresponding source code