I'm trying to insert a string stored in a variable with sed as follows:
sed -i "s/^GRUB_CMDLINE_LINUX_DEFAULT.*/$kernel_options/g" /etc/default/grub
Line that I am trying to replace is:
GRUB_CMDLINE_LINUX_DEFAULT=""
Variable is:
kernel_options="GRUB_CMDLINE_LINUX_DEFAULT=\"cryptdevice=${target_disk}${disk_append}2:luks:allow-discards resume=\/dev\/lvm\/swap mem_sleep_default=deep i915.enable_psr=0 i915.enable_fbc=1 i915.enable_guc=2\""
${target_disk}
and ${disk_append}
are determined earlier with:
target_disk=$(dialog --clear --title "Harddisk" --radiolist "Please select the target device" 0 0 0 \
$(ls /dev/sd? /dev/vd? /dev/mmcblk? /dev/nvme?n? -1 2> /dev/null | while read line; do
echo "$line" "$line" on; done) 3>&1 1>&2 2>&3)
if test $? -eq 1; then exit 1; fi
if grep -q "mmcblk" <<< $target_disk || grep -q "nvme" <<< $target_disk; then
disk_append=p
fi
I can't seem to get the sed part working, any suggestions how to improve this are appreciated.
Thank you in advance.