Created
October 18, 2019 21:38
-
-
Save jxu/87ce3142ea91c051e6fb1ef5c257ced8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Executing grep every time is a little slow, but bash regex doesn't support | |
# lazy evaluation and it's not worth rewriting... | |
IFS='' # Preserve whitespace for read | |
while read p; do # Read /boot/grub/grub.cfg line by line | |
LINE_REGEX=`echo $p | grep -Po "menuentry ['\"]\K.+?(?=['\"])"` | |
if [ "$LINE_REGEX" ]; then | |
# Submenu lines begin with a tab, so lazy method is to check for that | |
if [ ${p::1} = ' ' ]; then | |
echo " $LINE_REGEX" | |
else | |
echo $LINE_REGEX | |
fi | |
fi | |
done < /boot/grub/grub.cfg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment