karlchen wrote: ⤴Fri Mar 12, 2021 3:26 pm
Question: Do I write my own shell scripts
Answer: Yes, I do. I would not trust the stuff, which somebody else has put together.
So let me share one of the very basic scripts, which I have created:
show_grub_menu.sh
Code: Select all
#!/bin/bash
#
# Programme: show_grub_menu.sh
# Function : display the menu and submenu entries from /boot/grub/grub.cfg
# Author : Karl <camouflaged>
# Date : 13-Sept-2020 22:22
#
grep entry /boot/grub/grub.cfg | awk -F"'" '{ print $2 }'
Very handy (at least for me). Output formatting could be nicer, but then it would no longer be a simple one-liner.
I use the bash history search to recall those long scripts. By adding a ~/.input file with these contents:
Code: Select all
$include /etc/inputrc
# command history search
"\e[A": history-search-backward
"\e[B": history-search-forward
"\e[C": forward-char
"\e[D": backward-char
# extended auto-completion with tab
set show-all-if-ambiguous on
set completion-ignore-case on
# colors
set colored-completion-prefix on
set colored-stats on
# misc
set blink-matching-paren on
set mark-symlinked-directories = on
Then I just type a few beginning letters of the command and press the up-arrow to scroll
through the previously used commands beginning with those letters.
I modify .bashrc to allow more commands and storage space for this, and I carry the
history forward from release to release.
Here is a script in my history that finds locations of grub.
Code: Select all
sudo fdisk -l 2>/dev/null | egrep "Disk /|/dev/" | sed "s#^/dev/#Part /dev/#" | awk '{print $2}' | sed 's/://' | xargs -n1 -IX sudo sh -c "hexdump -v -s 0x80 -n 2 -e '2/1 \"%x\" \"\\n\"' X | xargs -n1 -IY sh -c \"case \"Y\" in '48b4') echo X: GRUB 2 v1.96 ;; 'aa75' | '5272') echo X: GRUB Legacy ;; '7c3c') echo X: GRUB 2 v1.97 or v1.98 ;; '020') echo X: GRUB 2 v1.99 ;; *) echo X: No GRUB Y ;; esac\""
I maybe use it once a year but I would not want to type it. With the history search I typed sudo fdisk and the second up arrow press entered that entire command.
Everything in life was difficult before it became easy.