I am trying to use a nested loop so that I can get the urls I desire, while also renaming the downloaded files to be unique. I am not getting something right.
The outcome is that I have unique file names (exactly like I want), but then they all have the same content, not at all what I want.
Here is what I have:
for image_name in `cat $IMAGE_TEST`;
do
for manifest_url in `cat $MANIFEST_URL_LIST`;
do
curl -H "Authorization: Bearer $KC_ACCESS_TOKEN" $manifest_url > \
manifests/$image_name.json
done
done
I have also tried:
for image_name in `cat $IMAGE_TEST`;
do
while read -r manifest_url
do
curl -H "Authorization: Bearer $KC_ACCESS_TOKEN" $manifest_url > \
mainifests/$image_name.json
done < $MANIFEST_URL_LIST
done
and other combinations of this, but seem to be not seeing what I am missing. Please help!
$image_name.jsonwith every possible url, so only the last URL is saved.for var in $(anything)and its backtick-based alternative are generally bad practice -- see BashPitfalls entry #1. Use arrays instead:read -t image_names <"$IMAGE_TEST"; read -t manifest_urls <"$MANIFEST_URL_LIST"; for idx in "${!image_names[@]}"; do curl "${manifest_urls[$idx]}" >"manifests/${image_names[$idx]}.json"; done