Oihana PHP

programLocations.php

Table of Contents

Functions

programLocations()  : array<string, string|null>
Finds where a PATH finds each program, as a shell would.

Functions

programLocations()

Finds where a PATH finds each program, as a shell would.

programLocations(array<string|int, string> $programs, string $path) : array<string, string|null>

For each name, the first file of that name in the directories of the PATH, in their order. A file that is there but not executable is not found: the shell would not run it.

Asked of a PATH other than the current one, it tells what a program started elsewhere — by cron, by a service — will find, which is not what a session finds. Paired with completePath(), it says whether completing a PATH is enough.

Parameters
$programs : array<string|int, string>

The program names, as a command line spells them.

$path : string

The PATH to look in.

Tags
example
use function oihana\core\env\programLocations;

programLocations( [ 'tar' , 'nothing-by-that-name' ] , '/usr/bin:/bin' ) ;
// [ 'tar' => '/usr/bin/tar' , 'nothing-by-that-name' => null ]
author

Marc Alcaraz (ekameleon)

since
1.4.0
Return values
array<string, string|null> —

Each program, in the order given, with the file the PATH finds for it, or null.

On this page

Search results