<分区>
我想在 bash 中迭代成对的元素。在 Python 中,这是直截了当的:
x_list = [1, 2, 3, 4]
y_list = ["a", "b", "c", "d"]
for x, y in zip(x_list , y_list):
# here we have access to the values (i.e. the pairs are assigned to variables):
result = do_something(x, y)
print(result)
如何在 bash 中复制这样的行为?我需要将对的值存储到 for 循环内的变量中,以便我可以执行一些操作。它应该是这样的:
for x, y in 1a 2b 3c 4d
do
python script.py --x_value=${x} --y_value=${y}
done
请注意,列表的元素也可以是复杂的东西,例如:
x_list = [1e-5, 1e-4, 1e-3]
和 y_list = [10, 20, 30]