diff --git a/linux-boot-probes/mounted/common/40grub2 b/linux-boot-probes/mounted/common/40grub2 index 885614e..ac44649 100755 --- a/linux-boot-probes/mounted/common/40grub2 +++ b/linux-boot-probes/mounted/common/40grub2 @@ -43,19 +43,23 @@ parse_grub_menu () { menuentry) entry_result shift 1 - # The double-quoted string is the title. - # Make sure to look at the text of the line - # before 'set' mangled it. - title="$(echo "$line" | sed -n 's/[^"]*"\(.*\)".*/\1/p' | sed 's/://g')" - if [ -z "$title" ]; then - # ... or single-quoted? Be careful - # to handle constructions like - # 'foo'\''bar' (which expands to - # foo'bar, as in shell), and to - # handle multiple single-quoted - # strings on the same line. - title="$(echo "$line" | sed -n "s/[^']*'\(\([^']\|'\\\\''\)*\)'.*/\1/p" | sed "s/'\\\\''/'/; s/://g")" + # title could be single- or double-quoted so determine which is used + delimiter=$(printf "%c" "$1") + if [ -n "$delimiter" ]; then + # strip everything up to and including the first delimiter + title_raw="${line#*${delimiter}}" + case "$delimiter" in + "'") + # handle constructions like 'foo'\''bar' which expands + # to foo'bar + title_raw="$(echo "$title_raw" | sed "s/'\\\\''/'/")" + ;; + esac + # strip everything after the matching delimiter + # (which will always be followed by a space) + title="${title_raw%%${delimiter} *}" fi + title="$(echo "$title" | sed 's/://g')" if [ -z "$title" ]; then ignore_item=1 elif echo "$title" | grep -q '(on /dev/[^)]*)$'; then