bash array crawler

I wanted to complement my bash directory crawler post with a bash array crawler example.

Sometimes, it’s easier to jack a list of identifying tokens into an array and process them rather than to build an end-to-end script with database access. For this contrived example, I grab a list of UUID from MySQL with a simple SQL statement.

mysql> SELECT id, uuid FROM icons;
+-----+--------------------------------------+
| id  | uuid                                 |
+-----+--------------------------------------+
|   1 | fe0b16ed-3369-4dda-8e60-faffb966375d |
|   3 | 82bfcbc2-84a2-4ca7-914b-13172b94feb6 |
|   6 | ab5e7265-3698-4205-b081-e6aec528fee2 |
|  11 | 4b6ca26b-c6ed-494f-aeb4-9bf369e2d465 |
|  19 | e7cc807b-7f15-46fa-b1c5-85d1f1050155 |
+-----+--------------------------------------+
5 rows in set (0.00 sec)

Next, jack the tokens into an array and simply crawl over the tokens.

#!/bin/bash

uuids=(
 fe0b16ed-3369-4dda-8e60-faffb966375d
 82bfcbc2-84a2-4ca7-914b-13172b94feb6
 ab5e7265-3698-4205-b081-e6aec528fee2
 4b6ca26b-c6ed-494f-aeb4-9bf369e2d465
 e7cc807b-7f15-46fa-b1c5-85d1f1050155
)

for uuid in ${uuids[@]} ; do

  # do something interesting here
  echo "http://icons.example.com/${uuid}.jpg"

  # curl 
  #   --request GET 
  #   --remote-name 
  #   --url "http://icons.example.com/${uuid}.jpg"

done

Your email will never published nor shared. Required fields are marked *...

*

*

Type your comment out: