This is a simple script which runs nvidia-smi command on multiple hosts and saves its output to a common file. The goal here is to make it run asynchronously. Is & at the end of the process_host() function call sufficient? Is my script correct?#!/bin/bashHOSTS=(host1 host2 host3)OUTPUT_FILE=nvidia_smi.txtrm $OUTPUT_FILEprocess_host() {    host=$1    echo Processing $host    output=`ssh ${host} nvidia-smi`    echo ${host} >> $OUTPUT_FILE    echo $output >> $OUTPUT_FILE}for host in ${HOSTS[@]}; do    process_host ${host} &done;waitcat $OUTPUT_FILE
Running multiple bash functions in the background and waiting until they return
bash;background process
Yes, but your output may be garbled.  It's better to have the function write its output to a specific file depending on the host name and then let the main script concatenate the result (and clean up).Also, you should double quote your variables. Copy and paste the script into ShellCheck.Maybe something like this:#!/bin/bashhosts=( host1 host2 host3 )outfile=nvidia_smi.txtrm -f $outfilefunction process_host {    local host=$1    local hostout=$host.out    printf Processing host '%s'\n $host    echo $host >$hostout    ssh ${host} nvidia-smi >>$hostout}for host in ${hosts[@]}; do    process_host ${host} &donewaitfor host in ${hosts[@]}; do    hostout=$host.out    cat $hostout >>$outfile    rm -f $hostoutdonecat $outfile