Trying to execute a function with an & so the For Loop will continue to execute without waiting for the job to be done.

My Function

perform_hdparm() {
hdparm -t "$1" | awk '/seconds/{print $11}'}

The For Loop

for drive in ${hddletter[@]}; do
printf '%s: %s\n' "$drive" "$(perform_hdparm "$drive")"

The Array contains

/dev/sda /dev/sdb /dev/sdk

So where do I put the & at to make things continue or can I? Just trying to speed things up.

Thank you

有帮助吗?

解决方案

Add it after the command you want to run in the background:

for drive in "${hddletter[@]}"
do
  printf '%s: %s\n' "$drive" "$(perform_hdparm "$drive")" &
done
wait
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top