0

Environment : KornShell (ksh)

I am exporting variables using:

eval $(echo '"EffTimeStamp=20110203-210000#InputCtxNm=Forigen Exchange Today#RunType=EOD"' |  
sed 's/^"/export /g;s/=/="/g;s/#/"\nexport /g')

And trying to display values of these variables dynamically:

eval $(echo EffTimeStamp=20110203-210000#InputCtxNm=Forigen Exchange Today#RunType=EOD|sed 's/^/echo $/g;s/=/="/g;s/#/"\necho $/g' | sed  's/=.*$//g')

But I am getting output as :

20110203-210000 echo Forigen Exchange Today echo EOD

I am not able to figure out why extra echo(s) is(are) displayed in it this not a satisfactory Output. It should be like below:

20110203-210000 
Forigen Exchange Today 
EOD
manuell
  • 7,528
  • 5
  • 31
  • 58
James Bond
  • 2,825
  • 2
  • 15
  • 11

1 Answers1

1

The way you are performing substitutions discards newlines. So the output of what's inside your parentheses looks like this:

echo $EffTimeStamp
echo $InputCtxNm
echo $RunType

But when you pass this to eval as eval $(...), you effectively get:

echo $EffTimeStamp echo $InputCtxNm echo $RunType

...which hopefully makes it obvious where the extra echo's are coming from. If you just add a semicolon to end of each line to mark an explicit end-of-command, it should do what you want:

eval $(echo EffTimeStamp=20110203-210000#InputCtxNm=Forigen Exchange Today#RunType=EOD|sed 's/^/echo $/g;s/=/="/g;s/#/"\necho $/g' | sed  's/=.*$/;/g')

The output of which is:

20110203-210000
Forigen Exchange Today
EOD
larsks
  • 277,717
  • 41
  • 399
  • 399