1

I have two bash variables, one called GREP_ENTRY, which contains a long string:

GRUB_CMDLINE_LINUX="crashkernel=auto spectre_v2=retpoline rd.lvm.lv=d6c-2b-59-93-97-ea/lv_root rhgb quiet console=tty0

and the other is called NEW_ENTRY, which is the exact same as GREP_ENTRY but with fips=1 appended to the end:

GRUB_CMDLINE_LINUX="crashkernel=auto spectre_v2=retpoline rd.lvm.lv=d6c-2b-59-93-97-ea/lv_root rhgb quiet console=tty0 fips=1

I am trying to use sed to find GREP_ENTRY in /etc/default/grub and replace it with NEW_ENTRY. Currently, I am trying to use double quotes as follows:

sed -i "s/$GREP_ENTRY/$NEW_ENTRY/g" /etc/default/grub

But I get the error:

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

I have tried using other combinations of double quotes but to no avail. Can someone explain how I can properly use sed in this situation?

  • Why not just `sed "/^GRUB_CMDLINE_LINUX=/s|^.*$|$NEW_ENTRY|" /etc/default/grub`? (add `-i` or `-i.bak` to edit in place, and/or create backup) – David C. Rankin Mar 19 '20 at 21:27

1 Answers1

2

Both variables contain /. That confuses sed's s command.

Switch from s/// to s|||.

Cyrus
  • 84,225
  • 14
  • 89
  • 153