Bash script loop through two variables in blocking step

I am trying to write a bash script that goes 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

      

The above code is clearly wrong. But I want me and j to move in a blocking step with each other. Can anyone help me on this to achieve this?

thank

+3


source to share


2 answers


#!/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

      



+2


source


Use arrays and a manual loop.



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

      

0


source







All Articles