error executing script in a while loop

Im unable to run scripts when i read each script thru a while loop. Is this way of execution thru while loop is wrong or is there any error in the script.

I get the following error msg and i use ksh.

./vftest.ksh[17]: ./add.ksh -customer 4875 -dim RD,TRND,TT,HS,MRKT,PRDC,ACV,CV,FCT: not found

contents of variable SCRIPT_LIST are

add.ksh -customer 4875 -dim RD,TRND,TT,HS,MRKT,PRDC,ACV,CV,FCT
div.ksh -customer 4875 -dim RD,TRND,TT,HS,MRKT,PRDC,ACV,CV,FCT
sub.ksh -customer 4875 -dim RD,TRND,TT,HS,MRKT,PRDC,ACV,CV,FCT
while read scrpt
                do
                        ./${scrpt} &
                        echo "Script running: ${scrpt}"
		sleep 10
                done < ${SCRIPT_LIST}

You get this error because you're passing the entire record as a single argument.

If the script names do not contain white spaces or other pathological characters, you could use eval, but it could be dangerous, because it will try to execute whatever string you pass to it:

eval "./$script &"

Another option is to assign the words (script name, options and arguments) to a different variables, something like:

while read _script _option1 _argument1 _option2 ...; do
  ./"$_script" "$_option1" "$_argument1" ... & 
done

Thanks! It seems to work with eval command. Can you pls tell me how the script runs when the eval command is used?

Because shell word splitting occurs before variable expansion, when you run the script like this:

./${scrpt} & 

the shell tries to execute the following command:

 ./"add.ksh -customer 4875 -dim RD,TRND,TT,HS,MRKT,PRDC,ACV,CV,FCT" &

So the shell is looking for a command named add.ksh -customer 4875 ..., not for command/script named add.ksh.

The argument passed to eval is evaluated twice, in your case first the variable is expanded, than the ordinary processing is attempted: redirection, shell word splitting, variable expansion (if any variable is left) etc, so the shell sees the correct command and executes it.

As I said, it would be safer to use the second approach.

Thanks much. I could use your 2nd option but the each scripts im running in the bg has different number of arguments to be passed. i.e other than these arguments

-customer 4875 -dim RD,TRND,TT,HS,MRKT,PRDC,ACV,CV,FCT

to the script there are other diff types of arguments/parameters need to be passed. Guess i could use $* in while loop to this approach.
I have this doubt: if im able to run the series of jobs in bg how can i confirm that all these series of jobs are running "only in bg" why because all these jobs are called thru the parent script

while read scrpt
                do
                        eval "./${scrpt} &"
                        echo "Script running: ${scrpt}"
		sleep 10
                done < ${SCRIPT_LIST}

Hence i guess there would be only one PID generated for this parent-script alone and not for the other scripts/jobs running inside the parent script.Pls advise.

You could use something like this (untested):

while read; do
  set -- "$REPLY"
  "$@"
done<your_file_name

I'm not sure I understand. If you need the pids of the background jobs:

$ cat s
printf 'echo %s\n' one two | 
  while read; do
    eval "$REPLY&"
        printf 'last pid --> %d\n' "$!"
  done
$ bash s
last pid --> 1596
one
last pid --> 3224
two

In my 1st post i have this script

while read scrpt
                do
                        eval "./${scrpt} &" # running the other scripts in backgound
                        echo "Script running: ${scrpt}"
        sleep 10
                done < ${SCRIPT_LIST}

where when this script is run it runs the other scripts thru the while loop in background.These other scripts (or the list of scripts to be run) are present in variable SCRIPT_LIST.How can we find the pid's of these other scripts.

As already mentioned, $! expands to the process ID of the most recently executed background command. You could save its value for further processing.