Question

I have an executable file to analyse an image . In the shell I write ./analyse img_001.jpg and it returns 1 number. I looked for a solution to analyse my 999 images ( img_001.jpg to img_999.jpg) with the use of a script ( i don't really wish to do it manually ) and I need a hint please.

Is it possible to have something like ./script.sh that returns me the 999 numbers?

Cordially

Was it helpful?

Solution

If you are using bash, you can simply use brace expansion:

for i in {1..999}; do
    printf "img_%03d.jpg\n" $i
done

This will print out:

img_001.jpg
img_002.jpg
...
img_998.jpg
img_999.jpg

To run your script using these as arguments you can use:

for i in {1..999}; do
    ./analyse $(printf "img_%03d.jpg" $i)
done

You could also replace the brace expansion with seq:

for i in $(seq 1 999); do
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top