In the "Command Search and Execution" section, the POSIX specification says that PATH is searched when finding a utility to execute (with some exceptions). Does the specification mention anywhere that PATH will be initialized to a value that guarantees that all standard utilities will be found?

Or do I need to do something like the following to guarantee that I'll never get a "command not found" error when trying to run a standard utility?

PATH=$(command -p sh -c 'printf %s "${PATH}"')

(see the POSIX specification of the command utility)

1 Answer 1


Yes and no. In a POSIX environment, the utilities must behave as described by the specification. In practice, this means that conforming versions of the utilities must be present in $PATH. However, when running your program on a POSIX-compliant system, you may be running it in a non-conforming environment. In practice, what often happens is that the OS has a legacy mode and a POSIX mode, and is in the legacy mode by default. Worse than missing some commands, the legacy mode tends to have incompatibilities in them, such as options with different meanings.

You can retrieve a good PATH with getconf. Of course, it's tricky, as getconf in the original $PATH may not be the right one. The Application Usage for command shows a way to do it:

command -p getconf PATH

As far as I understand the specification, this is not necessary if you are running your program in a POSIX-conforming environment; and if you aren't running your program in a POSIX-conforming environment, POSIX doesn't apply. However, this application usage can be taken as a recommendation: if this doesn't work, you can feel entitled to complain to your vendor that whatever they are doing regarding the letter of the POSIX spec, they are not complying with its spirit.

  • Heh, I didn't even notice that getconf PATH in the application usage section. Thanks! May 24, 2012 at 3:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .