I am trying to write a script which will read inputs form user and process those files, I have issue reading the input parameters in a loop. Following is the script...
I run the script as ./Script.sh 3 table1 table 2 table3
NumberOfTables=$1
let TableCount=1
while [ ${NumberOfTables} -gt 0 ]
do
TableName='$'$TableCount
db2 "runstats on table ${TableName} and indexes all"
let TableCount=TableCount+1
let NumberOfTables=NumberOfTables-1
done
exit 0
here I am not able to capture table1 table2 and table3 in the loop it prints TableName as $1 $2 and $3 but not the names that are given as input.
Having trouble following your logic, but perhaps the following thoughts will help this move along:
(1) The variable "$#" will be the number of parameters supplied. Thus, perhaps no need for the first 3 after your command because you could skip this and then do NumberOfTables="$#"
(2) The shift function allows a script to keep processing references to $1. Thus, you would do your first set of commands and then do a shift. Shift moves what is in $2 to $1, $3 to $2, etc... ; what was in $1 is now gone.