0

I would like to run the executable run_ex multiple times varying some parameters (text file), but I am new to the bash scripts and I can't figure out how to do that...

#! /bin/bash
for ((hour=1; hour <= 9 ; hour++))
do
   printf "run executable for hour %d \n" $hour

   parameter1 ="/path1/file1_$hour.txt" 

   parameter2 = "/path2/file2_$hour.txt" 

   ./run_ex $parameter1 $parameter2

done

Thanks

2 Answers 2

3

spaces are not allowed around = for variable assignment:

  parameter1 ="/path1/file1_$hour.txt" 
  #         ^

Write that instead:

  parameter1="/path1/file1_$hour.txt" 
  parameter2="/path2/file2_$hour.txt" 
Sign up to request clarification or add additional context in comments.

Comments

1

Following Sylvain Leroux's answer, you should also place your variables inside double-quotes to prevent word splitting and unexpected pathname expansion:

#!/bin/bash
for ((hour=1; hour <= 9 ; hour++))
do
    printf "run executable for hour %d \n"" $hour"

    parameter1="/path1/file1_$hour.txt" 
    parameter2="/path2/file2_$hour.txt" 

   ./run_ex "$parameter1" "$parameter2"
done

Also with brace expansion, you can simplify for ((hour=1; hour <= 9 ; hour++)) as for hour in {1..9}; do.

See Word Splitting and Pathname or Filename Expansion.

Comments

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.