Skip to main content
dash, oh well.
Source Link
Stephen Kitt
  • 480.9k
  • 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.

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.

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.

Add a maxdepth variant.
Source Link
Stephen Kitt
  • 480.9k
  • 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.

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-*"

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.

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.

Source Link
Stephen Kitt
  • 480.9k
  • 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-*"

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.