#!/bin/sh
#
# find-exec - find files matching pattern (arg1) and execute command (arg2, default: file) on them

set -eu

# default pattern to empty string if $1 is not provided
pattern="${1:-}"
# default command to 'file' if $2 is not provided
command_to_exec="${2:-file}"

# use find -print0 and xargs -0 for safety with filenames containing special chars
# use "$pattern" to handle potential spaces or special chars in pattern itself
# using -iname for case-insensitive search as in the original zsh function
find . -type f -iname "*${pattern}*" -print0 | xargs -0 -r "${command_to_exec}"
