cmd:eval, substitution of varible value 

! >How can I substitute one part of variable into anthor string?

! >I just can't make it work. See bellow: ! > ! >sh << eof ! >echo "" ! […] ! >echo "" ! ! When you use <<string, variables are interpolated while the here-document ! is being read by the original shell. So the "echo $x" and "echo $y" ! commands in your here-document are using whatever values $x and $y had in ! the original shell, not their values that are being assigned in the ! subshell. ! ! Try putting your commands in a separate shell script file, or use ! sh <<'eof' ! ! When you use <<'string', it indicates that the here-document should be read ! in as if everything were quoted, so no interpolation is done.

> changing your `sh' to `sh -x' will let you
> see exactly what is happening:
> cmd=echo $x | sed "s/xxx/yyy/"
> + echo $x | sed "s/xxx/yyy/"
> + eval x=$x | sed "s/xxx/yyy/"
> + sed s/xxx/yyy/
> x=---xxx---
> + echo ---xxx---
> ---xxx---
>
> the command substitution on the line with the eval, you will note,
> gets expanded before the eval happens, meaning all the eval sees as
> a command line to evaluate is "x=$x".  so what happens is that you
> assign x to itself, and then pipe the output of that (which is nothing)
> to the sed command.

FYI, the following code works:

sh -vx << 'eof'
echo "###"
x="---xxx---"
cmd='eval echo $x | sed "s/xxx/yyy/"'
x=`$cmd`
echo $x
echo "###"
eof
>>
cmd='eval echo $x | sed "s/xxx/yyy/"'
cmd=eval echo $x | sed "s/xxx/yyy/"
x=`$cmd`
+ eval echo $x | sed "s/xxx/yyy/"
+ + sedecho ---xxx---
 s/xxx/yyy/
x=---yyy---
echo $x
+ echo ---yyy---
>>

documented on: 1999.09.04 Sat 19:46:40