Usage of sed, position of apostrophe

Hello,
I have never ever seen below notation for string substitution.

sed -i -e 's/tttt/pppp'/g /var/bin/czech.sh;

The strange thing for me is the position of the apostrophe. Should it be before the / or after the g ?
If I had been writing that command line, I would have chosen below way:

sed -i -s 's/tttt/pppp/g' /var/bin/czech.sh

Could you please explain what it differs...
Is that about the operating system?

Many thanks
Boris

The quotes are there in instruct the shell (with regards, for example, to the expansion of shell variables in the case of using single quotes - where the shell would not expand them). In this case, it generally doesn't matter whether you put the closing quote before or after the g .

$ echo 123123 | sed 's/3/_THREE_/g'
12_THREE_12_THREE_
$ echo 123123 | sed 's/3/_TH'REE_/g
12_THREE_12_THREE_

But it is important that you use the correct ones. e.g.

$ T=_THREE_

$ echo 123123 | sed '/s/3/$T/g'
12$T12$T

$ echo 123123 | sed 's/3/'$T/g
12_THREE_12_THREE_

$ echo 123123 | sed "s/3/$T/g"
12_THREE_12_THREE_

Logically, someone might ask "why put the closing quote there?", as it could look odd, but it's not so important with regard to your example.

1 Like

Thank you so much for your examples.

Kind regards
Boris

Regular expressions uses meta-characters. These are characters that have special meaning beyond the representation of the character. The shell has also meta-characters. Therefore in order to protect the meaning of these characters it must be quoted so it gets passed to sed as the regular expression intended.
In this case the quoting could be avoided all together sed s/tttt/pppp/g /var/bin/czech.sh since there are no meta-characters.