0

I have a bash script that needs to take 4+ files, I would love to have a way to declare a variable name with a number for any of the files after the 4th one.

What I was thinking was some sort of while loop to declare a name based on a variable which looks at the number of a file after the 4th one, takes 3 away (so it numbers this new variable as the "1st" of the ? number of extra files.

I may not have explained this well

if [[ $# -lt 4 ]]; then
   echo "correct use is"
   echo "./UAT.sh input.inp expOut.exp actOut.act then whatever number of .bld files"
else
   input=$1
   exp=$2
   act=$3
   numFile=3
   while [[ ${numFile} -lt $# ]]; do
      (( numFile++ ))
      declare -i bldNum=${numFile}-3
      bld$bldNum=${!numFile}
   done
   echo "bld1 is ${bld1}"
   echo "bld2 is ${bld2}"
   echo "bld3 is ${bld3}"
fi

The third line in my while loop appears to be where I am having my trouble, when I try to run this program is says:

./newUAT.sh: line13: bld1=b1.bld: command not found

which seems very close to what I want, but I need to have a '$' before the 'b1.bld' in order to assign the variable. But it seems as though if I put an extra '$' the script also doesn't like it or it I put a '$' it similarly doesn't work. Any help or ideas?

0 Answers0