I'm trying to use sed in a script to modify a line in my grub configuration file(/boot/grub/grub.cfg
) each time grub updates. I wish to replace the following line:
menuentry "Kali GNU/Linux"
with this:
'menuentry "Kali GNU/Linux" --class kali'
The line in /boot/grub/grub.cfg is as follows:
menuentry "Kali GNU/Linux" --class gnu-linux --class os $menuentry_id_option 'osprober-gnulinux-/boot/vmlinuz-5.14.0-kali2-amd64--7afb9c25-9d47-4ce4-a3dd-635aa0b04d7a'
Basically, what I want to do is add the line --class kali
. I cannot replace gnu-linux
or os
with kali
as those words occur multiple times.
The script I've used is as follows:
TARGET_STRING='menuentry "Kali GNU/Linux"'
NEW_STRING='menuentry "Kali GNU/Linux" --class kali'
sudo sed -i "s/$TARGET_STRING/$NEW_STRING/g" /boot/grub/grub.cfg
This fails to work, giving the following error:
sed: -e expression #1, char 32: unknown option to `s'
I've found solutions online for substituting a string containing spaces here and substituting a string containing double quotes here, but not when a string contains both.
Could someone please help me out?
Note: I am using GNU sed 4.7
/
, confusing sed)sudo sed -i "s@$TARGET_STRING@$NEW_STRING@g" /boot/grub/grub.cfg
it is less error sources on special characters & characters that are used in the sed request syntax.