Skip to main content
3 of 3
dash, oh well.
Stephen Kitt
  • 481k
  • 59
  • 1.2k
  • 1.4k

With Bash you can use mapfile to split the path into array entries, safely, and then process that (with some special handling for newlines, see Mapfile not removing trailing newline):

readarray -t -d: p <<<"$PATH"
find "${p[@]%$'\n'}" -name "gcc-*"

or perhaps more usefully,

find "${p[@]%$'\n'}" -maxdepth 1 -name "gcc-*"

This separates the contents of $PATH using a colon as the delimiter, removing the colon from each entry, and storing the result in the array p. It then gives the individual entries in p as arguments to find, removing any trailing newline.

Since you’re using dash, you can’t use arrays, I think the best solution is to rely on the shell splitting $PATH using IFS — see Stéphane Chazelas’ answer.

Stephen Kitt
  • 481k
  • 59
  • 1.2k
  • 1.4k