I currently have something of the form
abc=`find ~/$folder .. etc
I'd like to know how to get the number of items in abc:
abc_length = ?
Thanks
I currently have something of the form
abc=`find ~/$folder .. etc
I'd like to know how to get the number of items in abc:
abc_length = ?
Thanks
I'm not sure what you mean by "items", so I will assume "directory entries". Assuming you have no files with newlines in their name, echo "$abc" | wc -l
will do the trick.
If you want to count the number of characters, use wc -c
instead.
Use array:
abc=( $(find ...) )
abc_length=${#abc[@]}
Retrieve n-th result, say 10th:
echo ${abc[9]}
Or list all:
for dir_name in "${abc[@]}"; do
echo $dir_name
done
Update: asker doesn't seem to want to process in script, so:
abc_length=$(find ... | wc -l)
You may want to reduce the number by 1 because the first result is ~/$folder
:
abc_length=$(( $(find ... | wc -l) - 1 ))