0

I have images in a sub-folder. Let's the folder images

I have a python program which will take image arguments from the folder one by one, the images are named in sequential order (1.jpg , 2.jpg, 3.jpg and so on).

The call to the program is : python prog.py 1.jpg

What will be a shell script to automate this ?

Please ask for any additional information.

2
  • first get all file names from folder. Run for loop for running python script for all files. Commented Jun 4, 2019 at 6:00
  • @HarshaBiyani sir I have no experience in writing shell scripts Commented Jun 4, 2019 at 6:02

3 Answers 3

1

Try this from the folder that contains images/:

for i in images/*.jpg; do python prog.py $i done

Sign up to request clarification or add additional context in comments.

1 Comment

Rather than surround blocks of code with backticks, it is easier to select the code and click the {} button in the Formatting Toolbar near Bold and Italic. Or you can put 4 spaces at the start of each line.
0

You could do them all in parallel very simply with GNU Parallel like this:

parallel python prog.py ::: images/*.jpg

Or, if your Python writes to the current directory:

cd images
parallel python prog.py ::: *.jpg

Comments

0
cd IMG_DIR
for item in [0-9]*.jpg
do
 python prog.py $item
 echo "Item processed : $item"
done

You can also pass image dir as a shellscript argument

2 Comments

Since we are talking about POSIX shell here, $item needs to get quoted when passed to python, otherwise it would break if the image name has embedded spaces.
Also, since the OP is only interested in jpg file names starting with a digit, the loop should read for item in [0-9]*.jpg

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.