我试图编写一个循环遍历两个变量的bash脚本:
#!/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彼此锁定步骤。有人可以帮助我实现这个目标吗?
由于
答案 0 :(得分:2)
#!/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
答案 1 :(得分:0)
使用数组和手动循环。
a=(sd fd dir)
b=(storage file director)
for ((i = 0; i <= ${#a}; i++)); do
echo "restarting bacula ${b[i]} daemon"
/sbin/service "bacula-${a[i]}" restart
done