Quote:
Originally posted by peter.herlihy
So Both actually acheive teh same result now..although I coulnn't explain why mine does!
Well then, I'll take a crack at explaining your solution to you.
Inside single quotes, what you see is what you get. No character has any special meaning inside single quotes. So variables won't expand. A string like:
'$a'
will just be $a. The shell will not try to substitute the value of a variable called a. So in the line:
sed '$a\
we get exactly what we ask for. Inside single quotes, even the backslash is just another character. (And, btw, this means that there is no way to get a single quote inside single quotes...so 'you can't do that' won't work and there is no way to fix it with backslashes.)
When you want to use a variable inside single quotes, it won't work:
'something $var something'
isn't going to do it. So we must break that single quoted string into two single quoted string and put the variable between them:
'something '$var' something'
is actually good enough, but most folks will add {} whenever a variable touches non-blanks, not just other letters:
'something '${var}' something'
And finally, if the value of var has a string of blanks, we would need to protect them, so we would need single quotes around the variable:
'something '"${var}"' something'
And this get us to the syntax that you used. Your first single quoted string started on one line and finished on the next but otherwise it's pretty much what we have here.