This is a pretty basic bash script (3.2 on Mac). I am downloading 584 images from a site in order to create an album.
#!/bin/bash
urlFirst="http://150.216.68.252:8080/adore-djatoka/resolver?url_ver=Z39.88-2004&rft_id=http://150.216.68.252/ncgre000/00000012/00011462/00011462_ac_0"
urlSecond=".jp2&svc_id=info:lanl-repo/svc/getRegion&svc_val_fmt=info:ofi/fmt:kev:mtx:jpeg2000&svc.format=image/jpeg&svc.level=6"
for i in {1..584}
do
printf -v j "%03d" $i
url=$urlFirst$j$urlSecond
wget $url -O $j".jpeg"
done
What improvements should be made to this?
I understand that I could remove the variables in most cases but for debug purposes it was helpful to have them, as I could add basic echo statements.
I'm not very well versed in Bash scripting though (lots of basic scripts) - any improvements or best practices from Bash I'm missing would be appreciated.
$url
variable (wget "$url" ...
), otherwise the first&
will send the wget command into the background without the complete url. See unix.stackexchange.com/questions/171346/… \$\endgroup\$x="foo&bar"; echo $x
would act the same asecho foo&bar
. I forgot that the shell does not interpret things like;
and&
unless you useeval
. But I would encourage you to read the link I provided. I would definitely writewget "$url" -O "$j.jpeg"
with all variables quoted. \$\endgroup\$