I wrote the following script for finding the number of pdf and tex files from the current directory, including the subdirectories and hidden files. The following code is able to find the number of pdf files upto 2 levels of subdirectories below, but after that it tells that there are no sub directories....
#!/bin/bash
touch t.txt
k=`find -type d |wc -l`
k1=`expr $k - 1`
echo $k1
message1="*.pdf *.tex"
count=`ls -al $message1|wc -l`
find -type d > t.txt
i=2
while [ $i -le $k ]
do
kd=`head -$i t.txt|tail -1`
echo $kd
touch $kd/t.txt
cp t.txt $kd/t.txt
i=`expr $i + 1`
done
i=2
while [ $i -le $k ]
do
nd=`head -$i t.txt|tail -1`
set -x
echo $nd
set +x
cd $nd
j=`ls -al $message1|wc -l`
count=`expr $count + $j`
i=`expr $i + 1`
done
#set +x
echo $count
set
and$#
? – pbm Mar 23 '12 at 15:46num=$(set -- **/*.pdf **/*.tex; echo "$#")
. – G-Man Says 'Reinstate Monica' Apr 15 '21 at 01:19globstar
,dotglob
, andnullglob
features to function, and those are almost certainly nonexistent. – Chris Down Apr 15 '21 at 15:33