cmdglob 336 B

1234567891011121314151617181920
  1. #!/bin/sh --
  2. set -ue
  3. GLOB="${1:?glob pattern not specified}"
  4. shift
  5. : "${1:?command not specified}"
  6. trap 'echo "glob failed" 1>&2; exit 1' USR1
  7. main="${$}"
  8. (
  9. eval "set -- ${GLOB}"
  10. [ "${#}${GLOB}" != "1${GLOB}" ] || {
  11. kill -s USR1 -- "${main}"
  12. exit
  13. }
  14. for path; do printf '%s\0' "${path}"; done
  15. ) | xargs -0o -I% -P1 -- "${@}"