I am using the FIND command on a number of directories stored in FDIR array to execute HEAD on each file. How can I adapt the code so users can also include files as well as directories?
hn=8 nf=${#fdir[@]} for (( i=0 ; i < $nf ; i++ )); do find "${fdir[$i]}" -type f \ -exec head -v -n "$hn" '{}' + done The synopsis of the GNU find command is find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point...] [expression] where [starting-point...] is zero or more paths. There is nothing stopping the user from passing files as starting points Example, given: $ cat subdir/somefile foo bar baz then $ find subdir/somefile - type f - exec head -n 2 {} + foo bar I could just do find " ${fdir[@]} " - type f - exec head -v -n " $hn " '{}' + regardless of the mix of directories and files in FDIR. But is this the right and proper way to use the FIND command?