Skip to main content
Clarifying comment with previously excised code.
Source Link

There are problems with this idea of a colon in the path to an executable, specifically with using said path in the PATH environment variable as in PATH="/home/bballdave025/abc\:def:$PATH". In fact, there are enough problems that I've decided to take this part of my solution out, since the problem isn't really ... real. However, I leave a reference to Note 3, in case someone has no control over a colon being in the path of an executable.

There are problems with this idea of a colon in the path to an executable, specifically with using said path in the PATH environment variable. In fact, there are enough problems that I've decided to take this part of my solution out, since the problem isn't really ... real. However, I leave a reference to Note 3, in case someone has no control over a colon being in the path of an executable.

There are problems with this idea of a colon in the path to an executable, specifically with using said path in the PATH environment variable as in PATH="/home/bballdave025/abc\:def:$PATH". In fact, there are enough problems that I've decided to take this part of my solution out, since the problem isn't really ... real. However, I leave a reference to Note 3, in case someone has no control over a colon being in the path of an executable.

Extending previous edit, specifically with `%s` given to all `printf`s.
Source Link

Edit: I've learned a lot by answering this question and receiving great suggestions about how to fix problems and make things better. I've left mostsome of my "learning" here in Notes after the answer, but I'm taking out some extraneous stuff, specifically concerning a file-path that contains a colon (':'). Hopefully everything remaining will be useful.

printf %s "$PATH" | tr ':' '\0' |     
    xargs -0 sh -c '
      find "$@" -mindepth 1 -maxdepth 1 -type f -name "gcc-*" 2> 
        >( grep -v "Permission denied\|No such" >&2)
    ' sh
printf %s "$PATH" | tr ':' '\0' |     
    xargs -0 sh -c '
     { find "$@" -mindepth 1 -maxdepth 1 -type f \
                 -name "gcc-*" 2>&1 >&3 | 
         grep -v "Permission denied\|No such" >&2; } 3>&1' sh

There are problems with this idea of a colon in the path to an executable, specifically with using said path in the PATH environment variable. In fact, there are enough problems that I've decided to take this part of my solution out, since the problem isn't really ... real. However, I leave a reference to Note 3, in case someone has no control over a colon being in the path of an executable.

Things are more clear and concise in a comment (archived) on this (my current) answer by
@Stéphane-Chazelas,

PATH="/home/bballdave025/abc:def"PATH="/home/bballdave025/abc\:def" means a $PATH$PATH with two directories: /home/bballdave025/abc\/home/bballdave025/abc\ and defdef, there's not point trying to treat that :\: specially.

Edit: I've learned a lot by answering this question and receiving great suggestions about how to fix problems and make things better. I've left most of my "learning" here in Notes after the answer, but I'm taking out some extraneous stuff, specifically concerning a file-path that contains a colon (':').

printf "$PATH" | tr ':' '\0' |     
    xargs -0 sh -c '
      find "$@" -mindepth 1 -maxdepth 1 -type f -name "gcc-*" 2> 
        >( grep -v "Permission denied\|No such" >&2)
    ' sh
printf "$PATH" | tr ':' '\0' |     
    xargs -0 sh -c '
     { find "$@" -mindepth 1 -maxdepth 1 -type f \
                 -name "gcc-*" 2>&1 >&3 | 
         grep -v "Permission denied\|No such" >&2; } 3>&1' sh

There are problems with this. In fact, there are enough problems that I've decided to take my solution out, since the problem isn't really ... real. However, I leave a reference to Note 3 in case someone has no control over a colon being in the path of an executable.

Things are more clear and concise in a comment (archived) on this answer by
@Stéphane-Chazelas,

PATH="/home/bballdave025/abc:def" means a $PATH with two directories: /home/bballdave025/abc\ and def, there's not point trying to treat that :

Edit: I've learned a lot by answering this question and receiving great suggestions about how to fix problems and make things better. I've left some of my "learning" here in Notes after the answer, but I'm taking out some extraneous stuff. Hopefully everything remaining will be useful.

printf %s "$PATH" | tr ':' '\0' |     
    xargs -0 sh -c '
      find "$@" -mindepth 1 -maxdepth 1 -type f -name "gcc-*" 2> 
        >( grep -v "Permission denied\|No such" >&2)
    ' sh
printf %s "$PATH" | tr ':' '\0' |     
    xargs -0 sh -c '
     { find "$@" -mindepth 1 -maxdepth 1 -type f \
                 -name "gcc-*" 2>&1 >&3 | 
         grep -v "Permission denied\|No such" >&2; } 3>&1' sh

There are problems with this idea of a colon in the path to an executable, specifically with using said path in the PATH environment variable. In fact, there are enough problems that I've decided to take this part of my solution out, since the problem isn't really ... real. However, I leave a reference to Note 3, in case someone has no control over a colon being in the path of an executable.

Things are more clear and concise in a comment (archived) on this (my current) answer by
@Stéphane-Chazelas,

PATH="/home/bballdave025/abc\:def" means a $PATH with two directories: /home/bballdave025/abc\ and def, there's not point trying to treat that \: specially.

Cutting out things that had become extraneous as things I'd shared got corrected. This was a good learning answer.
Source Link

Edited. Credit goes to @Stéphane-Chazelas for warning about using -maxdepth 1 without -mindepth 1 as well as for giving better usage of printf.

$ printf %s "$PATH" | tr ':' '\0' |
    xargs -0 sh -c 'find "$@" -mindepth 1 -maxdepth 1 -type f -name "gcc-*"' sh
/usr/bin/gcc-ar.exe
/usr/bin/gcc-nm.exe
/usr/bin/gcc-ranlib.exe

Edited. Credit goes to @Stéphane-Chazelas for warning about using -maxdepth 1 without -mindepth 1

$ printf "$PATH" | tr ':' '\0' |
    xargs -0 sh -c 'find "$@" -mindepth 1 -maxdepth 1 -type f -name "gcc-*"' sh
/usr/bin/gcc-ar.exe
/usr/bin/gcc-nm.exe
/usr/bin/gcc-ranlib.exe

Edited. Credit goes to @Stéphane-Chazelas for warning about using -maxdepth 1 without -mindepth 1 as well as for giving better usage of printf.

$ printf %s "$PATH" | tr ':' '\0' |
    xargs -0 sh -c 'find "$@" -mindepth 1 -maxdepth 1 -type f -name "gcc-*"' sh
/usr/bin/gcc-ar.exe
/usr/bin/gcc-nm.exe
/usr/bin/gcc-ranlib.exe
Cutting out things that had become extraneous as things I'd shared got corrected. This was a good learning answer.
Source Link
Loading
adding `sh` after the last single quote. Aligning shell arguments with `xargs` arguments
Source Link
Loading
Give a localizing version of the `IFS=` solution, so as not to set the main environment's `IFS`. Crediting @terdon.
Source Link
Loading
Fixing code to remove unnecessary scrolling of a code line (the line is split with a linefeed).
Source Link
Loading
added 3 characters in body
Source Link
Loading
Making changes for efficiency and correctness as per a comment by @Raffa. Removing `-I'{}'` from after `xargs` and putting double quotes around `$PATH`, so its expansion doesn't break paths with spaces in them.
Source Link
Loading
No need for \ after |, the | is a list terminator and you can move to a new line after it.
Source Link
terdon
  • 252.7k
  • 69
  • 481
  • 719
Loading
linking IFS solution, comments thereupon
Source Link
Loading
consistency of `sed 's ...` delimiter, matching OP's use
Source Link
Loading
Source Link
Loading