我想多次运行可执行文件run_ex来改变一些参数(文本文件),但我是bash脚本的新手,我无法弄清楚如何做到这一点......
#! /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
由于
答案 0 :(得分:3)
=
周围不允许空格:
parameter1 ="/path1/file1_$hour.txt"
# ^
改为写下:
parameter1="/path1/file1_$hour.txt"
parameter2="/path2/file2_$hour.txt"
答案 1 :(得分:1)
关注Sylvain Leroux's answer,您还应该将变量放在双引号内以防止分词和意外的路径名扩展:
#!/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
同样使用大括号扩展,您可以将for ((hour=1; hour <= 9 ; hour++))
简化为for hour in {1..9}; do
。