Issue
When I parse fortune database file with
$ mapfile -d '%' -t QUOTES < ~/.sigfile
$ echo ${#QUOTES}
302
$
However when I parse the same database with Python I get (correctly) much less length of the list:
>>> import re
>>> fort_arr = re.split(r"\n%\n", open("/home/matej/.sigfile").read())
>>> print(len(fort_arr))
202
>>>
Any idea what do I wrong? (and no, I couldn’t install /usr/bin/fortune
, all parsing must be done with plain bash and basic Unix utilities).
Yes, there is almost a duplicate, but it is closed and it does provide very awkward and complicated suggestions.
Solution
echo ${#QUOTES}
is the same as echo ${#QUOTES[0]}
, it prints the length of the first entry of the array. Try echo "${#QUOTES[@]}"
for the number of entries.
Answered By - Renaud Pacalet Answer Checked By - Marilyn (WPSolving Volunteer)