bash脚本在锁定步骤中通过两个变量循环 [英] bash script loop through two variables in lock step
本文介绍了bash脚本在锁定步骤中通过两个变量循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写一个循环遍历两个变量的bash脚本:
I'm trying to write a bash script that loops through two variables:
#!/bin/bash
for i in sd fd dir && j in storage file director
do
echo "restarting bacula $j daemon"
/sbin/service bacula-$i restart
echo
done
上面的代码显然是错误的.但我要我&j互相锁定.有人可以帮助我实现这一目标吗?
The code above is obviously wrong. But I want i & j to move in lock step with one another. Can someone help me with a way to achieve this?
谢谢
推荐答案
#!/bin/bash
a=(sd fd dir)
b=(storage file director)
for k in "${!a[@]}"
do
echo "restarting bacula ${b[k]} daemon"
/sbin/service "bacula-${a[k]}" restart
echo
done
这篇关于bash脚本在锁定步骤中通过两个变量循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文