titan titan - 10 months ago 68
Bash Question

Bash Script for running commands

I am trying to write a Bash script for running simulations and saving the output file in different directories. The code I have so far is:

mainDirCfg="/home/software/simplesim/simplesim-3.0/sim-outorder -config ../$1"
declare -a benchmark=("bzip2_base.i386-m32-gcc42-nn dryer.jpg" "equake_base.pisa_little <inp.in> inp.out")
declare -a directory=("bzip2" "equake")
for d in "${directory[@]}"
cd $d
cmdRun="$mainDirCfg $outFile $2 ${benchmark[$i]}"
# above is the command to be run
cd ..

The above script runs properly for the first iteration for not for the second one. However, on running the commands individually at the command prompt, I get the expected output. The command that I run for the second iteration is as follows:

/home/software/simplesim/simplesim-3.0/sim-outorder -config ../tmp.cfg -redir:sim tmp9.out equake_base.pisa_little <inp.in> inp.out

I am new to bash scripting. Can someone point out what the problem could be? Thanks.

Answer Source


cmdRun="$mainDirCfg $outFile $2 ${benchmark[$i]}"


eval "$mainDirCfg $outFile $2 ${benchmark[$i]}"

This is because your redirections in ${benchmark[1]} are seen as command arguments, as if they where quoted, not as true redirections. Your second program does not terminate because it waits forever for something to read from stdin, something you have to type since the redirection does not work (type Ctrl-D to close stdin and your script will continue).