Search code examples
bashshellgetopts

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:

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

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

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

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

How can I do this?


Solution

  • Try this for loop:

    for i in A B C; do
        ./test.sh -o c03 -d mydb -t tbl"$i" c13 -r us-east-1
    done