Automate the passing of parameters

I am writing a script that should read the csv file and pass the values in the file as parameters
to the script. The csv file looks like this:

TEST_1,20110221
TEST_2,20110220
TEST_3,20110218,20110219
 

Currently this is how i am running the script

./test.sh <param1> <date>

Ex: ./test.sh TEST_1 20110221 (from the above file)

./test.sh TEST_3 20110218 20110219
    

Now i should automate the script by reading through the file and pass the parameters to the script.

Please advice.
Thanks in Advance!!

Something like this:

   
        for i in `cat CSV_FILE`
        do
        file_name=`echo $i | cut -d"," -f1`
        params=`echo $i | cut -d"," -f2- | sed 's/,/ /g'`
        ./script.sh $file_name $params
        done
 

This would be simpler and faster:

eval "$(sed -e 's/,/ /g' -e 's/^/.\/script.sh /' file.csv)"

Thanks for the reply. This works absolutely fine.But i have a question.
The input file sometime contains 3 fields,
Ex: TEST_3,20100221,20100220
Can this code handle 3 fields?

Also if the fields are separated by "space" then this is how the code would look like:

for i in `cat input.txt`
        do
        file_name=`echo $i | cut -d"" -f1`
        params=`echo $i | cut -d"" -f2- | sed 's/ / /g'`
        ./yc_compute.ksh $file_name $params
        done

Thank You!!

---------- Post updated at 01:17 PM ---------- Previous update was at 12:57 PM ----------

@jlliagre: This one works fine too. Thanks for the reply!!

The panyam's cat solution don't work if there is spaces in the arguments.

As there is more than one way to do it, I'll post another solution :slight_smile:

cat test.csv | while read line; do ./test.sh $(echo $line | tr ',' ' '); done

But always beware of spaces in your arguments :slight_smile:

This should handle spaces in fields:

eval "$(sed -e "s/,/\\\" \\\"/g" -e "s/^/.\/script.sh \\\"/" -e "s/$/\\\"/" file.csv)"

This issue got resolved. Thanks a lot to each one of you for your help. Really appreciate!!