Last active
October 31, 2023 17:51
-
-
Save weezah/73ca3e69a3f5a83c3616aeb373d20efe to your computer and use it in GitHub Desktop.
Reboot to any grub entry
This file contains 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 | |
entries_array=() | |
function show_entries() { | |
echo | |
echo "Grub entries:" | |
echo | |
# Print the array elements | |
i=0 | |
for element in "${entries_array[@]}"; do | |
counter=$((counter+1)) | |
echo "${counter}. $element" | |
done | |
echo | |
} | |
function read_entries() { | |
while IFS= read -r line; do | |
entries_array+=("$line") | |
done < <(awk -F\' '/menuentry / {print $2}' /boot/grub/grub.cfg) | |
} | |
read_entries | |
show_entries | |
read -p "Select an entry: " choice | |
if (( choice >= 0 && choice <= ${#entries_array[@]} )); then | |
echo "Rebooting on $choice: ${entries_array[choice - 1]}" | |
sudo grub-reboot "${entries_array[choice - 1]}" | |
sleep 3 && sudo reboot | |
else | |
echo "Invalid index!" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment