Pass parameters to a function and running functions in parallel

Hi ,

I have a script which is using a text file as I/P.
I want a code where it reads n lines from this file and pass the parameters to a function and now this script should run in such a way where a function can be called in parallel with different parameters. Please find below my script, it is actually loading tables:

full()
{
echo "You entered full $1,$2,$3"
db2 "call util.DATA_REFRESH('LOAD','$1','$2','$3','$2','R','?',?)"  
rc=$?
if [ "$rc" -ne 0 ] ;then
echo "$1.$2" >>failure_list.txt
else 
echo "$1.$2" >>Success_list.txt
fi
}
schema=schema
table=table
nickname=nickname
 
split -l 4 full_refresh.txt
rc=$?
if [ "$rc" -ne 0 ] ;then
mutt -s "Unable to split" $mail_list
exit; 
fi
ls xa*  > list.txt
rc=$?
if [ "$rc" -ne 0 ] ;then
mutt -s "Unable to gather splitted file names" $mail_list 
exit;
fi
 
while read list
do
read_line=0
 
while read line1
do
read_line=`expr $read_line + 1`
echo $line1
eval "$schema""$read_line"=`echo $line1|awk 'BEGIN { FS = "|" } ; {print $1}'`
eval "$table""$read_line"=`echo $line1|awk 'BEGIN { FS = "|" } ; {print $2}'`
eval "$nickname""$read_line"=`echo $line1|awk 'BEGIN { FS = "|" } ; {print $3}'`
export "$schema""$read_line"
export "$table""$read_line"
export "$nickname""$read_line"
 
done < list
 
full $schema1 $table1 $nickname1 & full $schema2 $table2 $nickname2 & full $schema3 $table3 $nickname3 & full $schema4 $table4 $nickname4

Please check where am i going wrong.
full_refresh.txt: input file
here i tried using split command to read 4 lines at once.

Thanks a lot in advance

Well, quite possibly a lot. Is this for POSIX sh? If you have bash, you could use arrays instead of eval.

You should quote every "$variable".

You can test a command, rather than assign "$?" to a variable and test the variable... if takes a command ...

You should read your fields into separate values using read instead of `echo "$line" | awk '...'` ...

You write a "list.txt" but read a "list"

Taking all this into account, plus I don't think we need "split", I rewrite it as so:

#!/bin/sh
file='full_refresh.txt'
schema=schema
table=table
nickname=nickname

# i don't have this function...test
db2() {
        echo "db2: $@"
        #pretend like it takes some time
        sleep 10
}

full() {
        echo "You entered full $1,$2,$3"
        if db2 "call util.DATA_REFRESH('LOAD','$1','$2','$3','$2','R','?',?)"; then
                echo "$1.$2" >>Success_list.txt
        else
                echo "$1.$2" >>failure_list.txt
        fi
}

while IFS='|' read schema table nickname _; do
        count=$((count+1))
        full "$schema" "$table" "$nickname" &
        if [ "$count" -ge 4 ]; then
                wait
                count=0
        fi
done < "$file"