# SED help wanted



## balanga (Feb 17, 2017)

Could any SED expert help out with this small problem?

I have a short SED script which works using a file sedscr:

```
s/^/echo '/
s/$/' >>fubar/
```
which works fine with
`sed -f sedscr temp`
I'm trying to execute this as a single command:-
`sed  -e "s/^/echo '/" -e "s/$/' >>fubar/" temp`

but can't get it to work. The first part works, but the second part gives me an error

```
Illegal variable name.
```
The '$' is supposed to match the end of the line but seems to be getting misinterpreted.

Can anyone explain what I need to do/


----------



## SirDice (Feb 17, 2017)

balanga said:


> The '$' is supposed to match the end of the line but seems to be getting misinterpreted.


You need to escape it. It's because it's within a double quoted (") string which causes the shell to interpret $ as the start of a variable name (and $/ is obviously an illegal variable name).


----------

