# Sample of using array as command # Search script for using find and grep together to browse # directories searching for extension, then search for pattern. search() { local OPTIND=0 _o _usage _debug=false local -a _t _g _cmd=(find) read -rN9999 _usage <<-EOUsage Usage: $FUNCNAME [-a] [-d] [-i] [-I] [-H] [-l] [-t type [-t type]] \\ /path/ [path2/ ../path3/] pattern -t .ext specifying an extension to search for -d debug, will dump command variable before execution -[aiIHl] are 'grep' argument, see: man grep. many type and many path could be given but only one pattern. EOUsage while getopts 't:aiIHld' _o ;do case $_o in d) _debug=true ;; t) _t+=(${_t+-o} -name \*.${OPTARG}) ;; [aiIHl]) _g+=(-$_o) ;; *) echo "${_usage%$'\n'}" ; return 1 ;; esac done _cmd+=(${@:OPTIND:$#-$OPTIND} -type f) ((${#_t[@]})) && _cmd+=(\( "${_t[@]}" \)) _cmd+=(-exec grep ${_g[@]} ${@:$#} {} +) $_debug && declare -p _cmd "${_cmd[@]}" }