Help with script

#!/bin/ksh

values=`cat testvalue`
DATABASES=`echo "select agroup,tgroup from acc_gen..agroups where tgroup in ( $values )
go
" | isql -Uro -Pcup0fj0e -Sdev1client420 | grep acc_`

echo "$DATABASES"

When, I run the script it gives me result like
acc_fund2 KLU_LP
acc_fund3 KLU_LTD

But what I need is this way: acc_fund2 KLU_LP acc_fund3 KLU_LTD

Lets consider that values variable has two values like
'KLU_LP',
'KLU_LTD'

Can someone help on this?

Thanks.
Zulfiqar

use print or printf instead of echo

Vidhyadhar, it doesn't work. Actually I want to get values like "acc_fund2 KLU_LP acc_fund3 KLU_LTD". When I use echo $DATABASES it prints like acc_fund2 KLU_LP acc_fund3 KLU_LTD and when I use echo "$DATABASES" i get following out put:

acc_fund2 KLU_LP
acc_fund3 KLU_LTD

Any idea why and how resolve it?

Echo -n?

Doesn't work. Actually I want to get values like "acc_fund2 KLU_LP acc_fund3 KLU_LTD". When I use echo $DATABASES it prints like acc_fund2 KLU_LP acc_fund3 KLU_LTD and when I use echo "$DATABASES" i get following out put:

acc_fund2 KLU_LP
acc_fund3 KLU_LTD

Any idea why and how resolve it?

There's a newline in the text. With the "normal" echo it is split on the characters in $IFS, and echo reassembles them using $OFS. With the double quotes it's passed as-is. Try this:

echo "$DATABASE" | tr '\n' ' '

echo "$DATABASE" | tr '\n' ' ' doesn't display anything at all.

Then there's either something really wrong with the output from isql, or you mistyped:

$ DATABASE='acc_fund2 KLU_LP
> acc_fund3 KLU_LTD'
$ echo $DATABASE
acc_fund2 KLU_LP acc_fund3 KLU_LTD
$ echo "$DATABASE"
acc_fund2 KLU_LP
acc_fund3 KLU_LTD
$ echo "$DATABASE" | tr '\n' ' '
acc_fund2 KLU_LP acc_fund3 KLU_LTD 

I'm not sure what you want to accomplish. If you want DATABASES to be acc_fund2 KLU_LP acc_fund3 KLU_LTD regardless of echoing it with/without quotes, just add -n to this line: DATABASES=`echo -n "select agroup,tgroup from acc_gen..agroups where tgroup in ( $values ).

If you want the double quotes to be part of DATABASES' value, then something like this should do the trick:

DATABASES="\"`echo -n "select agroup,tgroup from acc_gen..agroups where tgroup in ( $values )\""

pludi/tetreb,

Below is my file contents:

#!/bin/ksh
values=`cat testvalue`
DATABASES=`echo -n "select agroup,tgroup from acc_gen..agroups where tgroup in ( $values ) go " | isql -Uro -Pcup0fj0e -Sdev1client420 | grep acc_`
echo "$DATABASE"

point me where I am wrong? Below is the out put I am getting:

jrc1sudev06:/export/home/client420 $ ./test.sh

jrc1sudev06:/export/home/client420 $

Thanks.
Zulfiqar

How about:

#!/bin/ksh

values=`cat testvalue`
DATABASES=`echo "select agroup,tgroup from acc_gen..agroups where tgroup in ( $values )
go
" | isql -Uro -Pcup0fj0e -Sdev1client420 | grep acc_`

echo "$DATABASES" > dbs

cat dbs | while read output_line
do
echo $output_line | awk '{print $1}' | read a
echo $output_line | awk '{print $2}' | read b
echo "$a"
echo "$b"
done

Brrr.... way too many UUOC-like pipes and alike for my taste.

Not tested, but you get the idea.....

#!/bin/ksh

read values < testvalue
printf "select agroup,tgroup from acc_gen..agroups where tgroup in ( %s )\ngo\n" "${value}" | isql -Uro -Pcup0fj0e -Sdev1client420 | grep 'acc_' | while read a b junk
do
    echo "$a"
    echo "$b"
done