我正在尝试编写一个通过两个变量循环的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彼此锁定。有人可以帮助我实现这一目标吗?
谢谢
#!/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
使用数组和手动循环。
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