0

I need to change a single line in the file /opt/google/chrome/google-chrome

exec -a "$0" "$HERE/chrome" "$@"

to

exec -a "$0" "$HERE/chrome" "$@" --test-type --no-sandbox

So my command is:

sed -i 's/exec -a "$0" "$HERE/chrome" "$@"/exec -a "$0" "$HERE/chrome" "$@" --test-type --no-sandbox/' /opt/google/chrome/google-chrome

Which returns:

sed: -e expression #1, char 37: unknown option to `s'

I have searched and found that characters in the command are confusing sed, but I can't seem to find an answer to which ones or how to form it properly. Can anyone help me to edit my command to the proper syntax?

  • 1
    You need to escape the slashes or use an alternate regex delimiter - see for example How to escape file path in SED? – steeldriver Sep 14 '22 at 16:34
  • you can check this out https://dwaves.de/tools/escape/ – Cagri Sep 14 '22 at 16:55
  • @IanPrice you'd replace the ones being used as sed delimiters - to distinguish them from the literal ones in the pattern and replacement text – steeldriver Sep 14 '22 at 16:57
  • Ok. I appreciate the replies, but I still don't get it. All I need to do is replace a line of text with another line of text. And I really do appreciate pointing me to resources to learn how to do it myself, but can anyone please just copy/edit my command and tell me the answer? I have been working on this silly thing for like 2 hours so far. – Ian Price Sep 14 '22 at 17:04
  • @glennjackman, THANK YOU! That was a great way to help me understand. – Ian Price Sep 14 '22 at 17:14

2 Answers2

1

Instead of s/pattern/replace/ use something like s!pattern!replace! (or a different character if you don't like !) -- this is because both the pattern and replacement string contain the / character.

Your sed command is

s/exec -a "$0" "$HERE/chrome" "$@"/exec -a "$0" "$HERE/chrome" "$@" --test-type --no-sandbox/
  • the pattern is exec -a "$0" "$HERE,
  • the replacement is chrome" "$@"
  • and then the flags (s/re/repl/flags) are exec
    • there is an e flag, but x and c are not recognized.

Also note that $ is a special character in a recular expression, and it needs to be escaped.

Try this:

s!exec -a "\$0" "\$HERE/chrome" "\$@"!&  --test-type --no-sandbox!
  • & in the replacement string is replaced with the text that matched the pattern

Alternately, for lines that match "exec ... chrome ...", add the flags to the end of the line:

\!exec -a "\$0" "\$HERE/chrome" "\$@"! s/$/ --test-type --no-sandbox/
glenn jackman
  • 17,900
0

Yes, thank you. What worked for me is:

sed -i 's!exec -a "$0" "$HERE/chrome" "$@"!exec -a "$0" "$HERE/chrome" "$@" --test-type --no-sandbox'! /opt/google/chrome/google-chrome