Next: , Previous: , Up: program   [Contents][Index]

11.2 Checking programs existence

The simpler way to test the availability of a program is to look for it just before it is used.

Array: mbfl_split_PATH

After a call to mbfl_program_split_path(): this array is filled with the components of the PATH variable.

Function: mbfl_program_split_path

If the number of pairs in the global array mbfl_split_PATH is zero: split the current value of PATH into its components by splitting the string using the colon character : as separator; store the result in the global array mbfl_split_PATH; finally return true.

If the number of pairs in the global array mbfl_split_PATH is not zero: do nothing and return false.

We can print the contents of the array with:

local -i i

for ((i=0; i < ${#mbfl_split_PATH[@]}; ++i))
do echo "${mbfl_split_PATH[$i]}"

To force a resplit, just reset the array to the empty state with:

Function: mbfl_program_find program
Function: mbfl_program_find_var _RV program

Search for a program in the standard search path. Print the full pathname of the program found, or an empty string if nothing is found. If an executable file is found: return true; otherwise return false.

The search path is the one in the environment variable ENV as found by mbfl_program_split_path(). The contained directories are searched in the order in which they appear in PATH. There are rules:

The _var function variant will store the result in the variable _RV rather than print it.

Next: , Previous: , Up: program   [Contents][Index]

This document describes version 3.0.0-devel.0 of Marcos Bash Functions Library.