I would like to be able to search all my
$PATH
for files matching a given pattern.
For example, if my PATH is /usr/local/bin:/usr/bin:/bin
and there's a /usr/local/bin/gcc-4
and a /usr/bin/gcc-12
, I would like to be able to search for gcc-*
to find them both.
The trivial approach of course does not work:
find ${PATH} -name "gcc-*"
this naive approach does work:
find $(echo "${PATH}" | sed -e 's|:| |g') -name "gcc-*"
but of course this is breaks if PATH holds any weird characters like space and the like.
So how can I achieve this in a safe way? My shell is sh
.
Asked by umläute
(6704 rep)
Jul 30, 2025, 12:35 PM
Last activity: Aug 6, 2025, 07:44 PM
Last activity: Aug 6, 2025, 07:44 PM