Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash script loop through two variables in lock step

Tags:

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

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

like image 245
bluethundr Avatar asked Oct 19 '25 01:10

bluethundr


1 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
like image 195
John1024 Avatar answered Oct 21 '25 22:10

John1024



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!