IFS(Internal Field separator)

Hi All,

I need your small help in using IFS.

I am using it like below but i am not getting the desired output.

var=ABCD,EFGH,IJKL,MNOP,QRST
export IFS=","
for x in $var
do
if [[ $GP == "" ]]
then
temp="Group_$x"
GP=${!temp}
else
temp="Group_$x"
MP="${!temp}"
GP="$GP","$MP"
 
fi
done
echo $GP

Seems IFS also applies on $GP whereas i want the output(GP) separted by comma(,)

Desired Output:
Model output is (valueof)ABCD, (valueof)EFGH, (valueof)IJKL, (valueof)MNOP

Obtained output:
(valueof)ABCD (valueof)EFGH (valueof)IJKL (valueof)MNOP

Any help !! Thanks in advance!

Try changing the last line in your script from:

echo $GP

to:

echo "$GP"

and changing the line:

GP="$GP","$MP"

to:

GP="$GP,$MP"

Another method is to save/restore IFS

var=ABCD,EFGH,IJKL,MNOP,QRST
oldIFS=$IFS
IFS=","
for x in $var
do
if [[ $GP == "" ]]
then
temp="Group_$x"
GP=${!temp}
else
temp="Group_$x"
MP="${!temp}"
GP="$GP","$MP"
fi
done
IFS=$oldIFS
echo $GP