1

As shown in the image below, I have a Linux executable and it can be run using this command:

./bomb filename0.txt

I need a bash script to run this continuously as I have various files that I want to run the executables with as shown in the picture such as filename0, filename1, filename and so on.

enter image description here

How could I automate the execution of my script with all these files as argument?

2 Answers 2

1

Use bash. This script will execute bomb on every file in your directory

for file in /path/to/dir/*.txt
do
  path/to/bomb "$file" >> results.out
done

Example

[20:37:04] ado@crystal
± >  touch a b c

[16:47:26] ado@crystal
± >  ls
a b c

[16:47:27] ado@crystal
± >  for i in *; do echo "this is $i"; done
this is a
this is b
this is c
Sign up to request clarification or add additional context in comments.

1 Comment

Be careful, this will pass bomb as an argument to itself. If the argument files names are consistent, consider filtering with *.txt to avoid that.
0
for i in `seq 0 10`
do
 ./bomb filename$i.txt
done

The above code will run from filename0 to filename10

2 Comments

Thanks !! I was mixed up the syntax with python as I put filename{1}!! No wonder
This works in this precise case, but you're limited to patterns where filenames contain a number you iterate on. I think aydow's answer is more generic.

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.