Мне кажется, что если проще использовать только sed, например, вот так:
sed -E -e "s/(^GRUB_CMDLINE_LINUX_DEFAULT=[\"'](|.* ))quiet ?(.*)/\1\3/" -e "s/(^GRUB_CMDLINE_LINUX_DEFAULT=[\"'](|.* ))splash ?(.*)/\1\3/"
Но на самом деле у меня есть и ответ на поставленный вопрос -- в пакете libshell есть shell-quote, в котором есть функции quote_sed_regexp и quote_sed_regexp_variable, по поводу которых в shell-quote(3) есть такие примеры:
quote_sed_regexp
Function quotes given arguments for sed basic regular expression. Usage example:
sed "s/$(quote_sed_regexp "$var_pattern")/$(quote_sed_regexp "$var_replacement")/"
quote_sed_regexp_variable
Function quotes argument for sed basic regular expression and stores result into variable. Usage example:
quote_sed_regexp_variable var_pattern "$pattern"
quote_sed_regexp_variable var_replace "$replace"
sed "s/$var_pattern/$var_replace/"
По поводу приведённого кода на bash -- можно сделать вот так:
#!/bin/sh -efu
. shell-quote
GRUB_CFG=/etc/sysconfig/grub2
GRUB_STR="$(sed -E "s/^GRUB_CMDLINE_LINUX_DEFAULT=['\"](.*)['\"]$/\1/" "$GRUB_CFG")"
set -- $GRUB_STR
NEW_STR=
for i; do
case "$i" in
quiet|splash) continue ;;
esac
NEW_STR="${NEW_STR:+$NEW_STR }$i"
done
sed "s/^GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT='$(quote_sed_regexp "$NEW_STR")'/" -i "$GRUB_CFG"