I tested the single quote and double quotes in sed
me@host:~:
$ echo "front" | sed "s/front/back/"
back
me@host:~:
$ echo "front" | sed 's/front/back/'
back
They performed identically, but I remembered to read there exist differences between them months ago.
Google search not helpful with keywords "single quotes and double quotes in sed".
They are not identically, right?
Best Answer
I'm expanding my earlier comments into an answer.
My advice would be sticking to single quotes, unless you know what you're doing and need to take advantage of some command-line functionality. The most common cases that come to mind are single quotes inside text strings and shell variable interpolation.
Here's a couple of examples where using double quotes makes perfectly sense:
It seems that double quotes enable some nice functionality, so why not always use them? The main reason for me is not always seeing what command is actually being executed by
sed
. It's very simple when the command is enclosed in single quotes: what you see is exactly whatsed
sees. When using double quotes, however, your string is going to be interpreted by the shell before being passed on tosed
, and you must take into account any modifications, some of which might not be what you want. Here's a good example:If you had used double quotes, here's what your actual
sed
command would have been like:You can often get away with double quotes in connection to
sed
, because use of the$
sign tends to be unambiguous:Things become more complicated if you're writing
awk
orperl
, where$
has more uses: