Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

12
  • 1
    Re your first example ... -I {} implies -L 1 thus reducing efficiency and the unquoted expansion of $PATH will break paths with spaces in them ... So, probably consider something like printf "$PATH" | tr ':' '\0' | xargs -0 sh -c 'find "$@" -maxdepth 1 -type f -name "gcc-*"' sh ... Also, although a minor thing, but the replace string {} when used doesn't need to be quoted as it doesn't undergoes shell expansion rather the arguments are written/placed on the command-line by xargs properly. Commented Jul 31 at 12:29
  • 1
    Thanks, @Raffa. I'll make the changes. I never knew what to use by default with xargs; I was always just taught -I '{}'. I should have tested those "weird character" conditions more thoroughly. Commented Jul 31 at 18:19
  • 1
    You're welcome ... The first position in the parameters after a command string in a shell i.e. sh -c '...' 1 2 3 is $0 and not $1 ... so you need to force xargs to start positioning arguments from $1 by preoccupying $0 with e.g. the name of the shell sh ... Compare the output of sh -c 'echo "$@"' 1 2 3 to sh -c 'echo "$@"' sh 1 2 3 Commented Aug 1 at 8:55
  • 1
    I also think it means that I need to add an sh after my sh -c '...'. @Raffa, does my code look correct, now? Commented Aug 1 at 20:01
  • 1
    Your redirections in { find "$@" -maxdepth 1 -type f -name "gcc-*" | grep -v "Permission denied\|No such" >&3; } 3>&2 2>&1 don't make much sense. Maybe you meant { find "$@" -maxdepth 1 -type f -name "gcc-*" 2>&1 >&3 | grep -v "Permission denied\|No such" >&2; } 3>&1 for grep to filter find's errors (assuming they're in English). Commented Aug 2 at 8:33