Passing directories and files

goncholden via Bug reports for the GNU find utilities <[email protected]>
Newsgroups gmane.comp.gnu.findutils.bugs
Message-ID <yBTFFPK3T75UdzM_Ur7b8erPUXPqMc7MBPMOcGiPoevzg7lFzeCPFizsm2MjKtWytHebwdtgQXFUn21g-rliAYLw7lODC74_MGQVdTLupSM=@protonmail.com>
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?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.