I am trying to run a bash script that controls my fans based on hdd temp.

In the script I can add my fan to "ARRAY_FAN=/sys/class/hwmon/hwmon4/pwm6"

So I am wondering how I can add multiple fans to the ARRAY_FAN variable so when the script changes rmp on ARRAY_FAN it actually changes the rpm on all fans, pwm5,pwm6,pwm7 and pwm8

Can I add /sys/class/hwmon/hwmon4/pwm5 to pwm8 as individual variables, then add them to ARRAY_FAN, or add multiple lines to the ARRAY_FAN value?

This is the script I am trying to use https://github.com/kmwoley/unRAID-Tools/blob/master/unraid_array_fan.sh

  • This is probably better asked on the aforementioned Github page. Feb 6, 2022 at 5:10
  • Hi Eirik and welcome to unix.stackexchange.com. Please always include the relevant part of your script into your post. Since your question seems to focus on how to modify an existing script in general, please quote only a relevant, self-contained part of the script in OP. Don't expect many people to actually go through the whole script and sort it out for you. Showing that you isolated the issue goes a long way toward getting good answers...
    – Cbhihe
    Feb 6, 2022 at 11:05
  • Does this help ?
    – Cbhihe
    Feb 6, 2022 at 11:48

1 Answer 1


For Bash version >= 4.0, you will find that an efficient way (of populating an array arr all at once) is to use the command mapfile, or its exact synonym readarray, as in:

mapfile -t arr < <(command)

Check your array content with $ declare -p arr and all available options and flags in your bash manual.

For example:

$ mapfile -t arr < <(seq 1 4)
$ declare -p arr
declare -a arr=([0]="1" [1]="2" [2]="3" [3]="4")

Expect this to fail in general if your command output contain globbing characters such as *. There are alternative ways of doing this here, an SO post by @gniourf_gniourf.

If your Bash version is older than 4.0, please indicate it for a solution not based on mapfile, along the line of:

IFS=$'\n' read -r -d $'\0' -a arr < <(command && printf '\0')

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .