4

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

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?

Thanks

2 Answers 2

4
#!/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
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.