Reputation: 3017
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
Upvotes: 0
Views: 239
Reputation: 311978
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
Upvotes: 1