Reputation: 5559
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
Upvotes: 0
Views: 4466
Reputation: 75488
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.
Upvotes: 1
Reputation: 52000
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"
Upvotes: 3