noober noober - 1 year ago 63
Bash Question

bash - how to iterate a list/array through a parameterized bash script

I have a bash script where I pass the following arguments (its using getopts) like so:

./ -o c03 -d mydb -t tblA -n c13 -r us-east-1

The execution works however, I need to alter this where
(for table) needs to be a list of tables
(tblA, tblB, tblC)

So, in a single run, I'm trying to generate the following:

./ -o c03 -d mydb -t tblA -n c13 -r us-east-1
./ -o c03 -d mydb -t tblB -n c13 -r us-east-1
./ -o c03 -d mydb -t tblC -n c13 -r us-east-1

How can I do this?

Answer Source

Try this for loop:

for i in A B C; do
    ./ -o c03 -d mydb -t tbl"$i" c13 -r us-east-1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download