bash - 如何通过参数化的 bash 脚本迭代 list/array
bash - how to iterate a list/array through a parameterized bash script
我有一个 bash 脚本,我在其中传递以下参数(它使用 getopts),如下所示:
./test.sh -o c03 -d mydb -t tblA -n c13 -r us-east-1
然而执行有效,我需要改变这个 -t
(对于 table)需要是 tables (tblA, tblB, tblC)
.[=17 的列表=]
因此,在单个 运行 中,我尝试生成以下内容:
./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
我该怎么做?
试试这个 for
循环:
for i in A B C; do
./test.sh -o c03 -d mydb -t tbl"$i" c13 -r us-east-1
done
如何利用 bash 并使用变量范围?如果您必须处理大范围,这将有所不同。
for i in {A..C}
do
./test.sh -o c03 -d mydb -t tbl"$i" c13 -r us-east-1
done
我有一个 bash 脚本,我在其中传递以下参数(它使用 getopts),如下所示:
./test.sh -o c03 -d mydb -t tblA -n c13 -r us-east-1
然而执行有效,我需要改变这个 -t
(对于 table)需要是 tables (tblA, tblB, tblC)
.[=17 的列表=]
因此,在单个 运行 中,我尝试生成以下内容:
./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
我该怎么做?
试试这个 for
循环:
for i in A B C; do
./test.sh -o c03 -d mydb -t tbl"$i" c13 -r us-east-1
done
如何利用 bash 并使用变量范围?如果您必须处理大范围,这将有所不同。
for i in {A..C}
do
./test.sh -o c03 -d mydb -t tbl"$i" c13 -r us-east-1
done