jamesisin
September 30th, 2010, 03:40 AM
I am building an array from a find command. I am having trouble with my syntax and presumably the problem is quotation marks.
read -p "Please provide the root folder under which I will work recursively: "
if [ -d "$REPLY" ]; then
printf "\nI have confirmed this is a directory.\n\n"
directory="$REPLY"
else
printf "\nI cannot confirm this is a directory.\n\n"
exit 1
fi
albumfind=""
declare -a albumfind
albumfind="( $( find "$directory" -type f -name \*.[Aa][Pp][Ee] -o -name \*.[Ff][Ll][Aa][Cc] ))"
a=${#albumfind } # count array
echo "The count is "$a" files."
printf "The array albumfind is "$albumfind", dog.\n\n"
for (( i=0; i<${a}; i++ ));
do echo ${albumfind[$i]}
done
printf "\n\nNothing to see here folks. This is how it ought to look.\n\n"
find $directory -type f -name \*.[Aa][Pp][Ee] -o -name \*.[Ff][Ll][Aa][Cc]
As you can see I am using the same find command twice in the script. However, no matter how I arrange my quotation marks I cannot get them to display the same results. The final line is working as expected (of course), but the array is either one element or 75 (compared to the actual count of 25).
Can someone help me with my syntax?
read -p "Please provide the root folder under which I will work recursively: "
if [ -d "$REPLY" ]; then
printf "\nI have confirmed this is a directory.\n\n"
directory="$REPLY"
else
printf "\nI cannot confirm this is a directory.\n\n"
exit 1
fi
albumfind=""
declare -a albumfind
albumfind="( $( find "$directory" -type f -name \*.[Aa][Pp][Ee] -o -name \*.[Ff][Ll][Aa][Cc] ))"
a=${#albumfind } # count array
echo "The count is "$a" files."
printf "The array albumfind is "$albumfind", dog.\n\n"
for (( i=0; i<${a}; i++ ));
do echo ${albumfind[$i]}
done
printf "\n\nNothing to see here folks. This is how it ought to look.\n\n"
find $directory -type f -name \*.[Aa][Pp][Ee] -o -name \*.[Ff][Ll][Aa][Cc]
As you can see I am using the same find command twice in the script. However, no matter how I arrange my quotation marks I cannot get them to display the same results. The final line is working as expected (of course), but the array is either one element or 75 (compared to the actual count of 25).
Can someone help me with my syntax?