Skip to content
Advertisement

Access List of Items from cURL Result

If u go to this url : http://artii.herokuapp.com/fonts_list, you will see a list of 417 items on the list.

I’m trying to create a variable to store/access those list.

I could not get it to work.

fontList=$(curl http://artii.herokuapp.com/fonts_list)
fontListCount=$(curl http://artii.herokuapp.com/fonts_list | wc -l)

for i in $(seq 1 $fontListCount);
do
    echo -e "I like this font --> " fontList[$i]
done

I kept getting

I like this font -->  fontList[1]
...
I like this font -->  fontList[417]

Any hints on how to do it ?

Advertisement

Answer

Starting with the assumption that the result is, in fact, one font name per line, you can use a single call to readarray:

readarray -t fontList < <(curl http://artii.herokuapp.com/fonts_list)

Then

for i in "${fontList[@]}"; do
  echo "I like this font --> $i"
done
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement