Categories: Linux

Doing a for loop in batch script

Let’s see you want to download a series of file from somewhere.
Which is having sequential filename.

This can be easily done with a shell script.
such as below:

for i in {1..113}
do
echo $i
done

while am at it, why not make a PDF file out of the images file.
this may require ImageMagick to be installed first.

yum install ImageMagick -y

So, the final script would be something like..


#!/bin/bash

  mkdir z
  cd z  
  for i in {1..113}
    do          
      # go get the image.
      /usr/bin/wget https://dev.namran.com/ss/IMAGE-$i.jpg -O $i.jpg
    done        
  # make pdf from jpg list
  convert `ls -1v` ../1st-session.pdf
  mv ../1st-session.pdf ~/public_html/download/


Done.

Namran Hussin

a soft spoken guy... with exceptional interest in computers and technology. I love to learn new thing and also love to break thing for the sake of learning.. but I do abide to the self-imposed limitation or certain thing such as social thing in life, thing can be done and thing that must be avoided at whatever cost such as drug,illegal tracking, smoke,illicit activity..etc.muahahaha let's share what we had in this short term of the life.! make it worth of the living.~

Leave a Comment
Share
Published by
Namran Hussin

Recent Posts

How you can speak with clarity and influence

Here are five key communication skills that help you speak with clarity and influence: Speak…

7 months ago

? Man360 Academy Q&A Session Video Access – Empower Your Masculine Growth Journey

Are you ready to unlock your full potential as a man?Discover powerful insights, real-life transformations,…

1 year ago

A note to remember

One day we will set aside one whole day to review the whole lesson we…

1 year ago

Dev Fest KL 2024

Last weekend, 07/12/2024 I managed to join Dev Fest Kuala Lumpur 2024, organized by Google…

1 year ago

TIPS BACAAN AL-QURAN

TIPS BACAAN AL-QURANOleh: Dr. Muhd al-Muhaysni.1. Jangan engkau berikan (fokus membaca) al-Quran pada lebihan waktumu…

2 years ago

Selawat 300 ribu kali

Selawat yang ringkas, yang mana apabila kamu membacanya satu kali sebanding 100 ribu kali, jadi…

2 years ago