The journey through the util-linux from the a package set of Slackware
continues. First, a tutorial on getopt, an argument parser for Bash and
Tcsh. Here is a demonstrative sample script:
#!/usr/bin/bash ## or you can just use /bin/sh
OPTS=getopt --options f --long foo --alternative -- "$@"
eval set -- "$OPTS" echo "Raw input: $OPTS"
while true ; do case "$1" in -f|--foo) echo "Option f has been toggled on" ; shift ;; --) shift ; break ;; esac done
# this outputs anything # left over after parsing # valid options for i in "$@" ; do echo "$i" done
You can add more options, and you can add an allowance for arguments. Here is a slightly more complex version of the script:
#!/usr/bin/bash
OPTS=getopt --options f,b: --long foo,bar: --alternative -- "$@"
eval set -- "$OPTS"
echo "$OPTS"
while true ; do case "$1" in -f|--foo) echo "Option f has been toggled on" ; shift ;; -b|--bar) echo "Option b has been set to $2" ; shift 2 ;; --) shift ; break ;; esac done
for i in "$@" ; do echo "$i" done
After the coffee break, Klaatu covers kill. Because he recorded this episode
on the same night as the previous episode, he does make reference to some
settings from the previous episode (specifically, a hostname setting). That
makes this episode a sequel to the previous one, meaning Klaatu owes you an
extra episode sometime.
Also, mountpoint, mount, unmount, wdctl and watchdog
gnu.org/software/libc/manual/html_node/Example-of-Getopt.html
A great article about the eval and set on Linux Journal
Watchdog daemon
Systemd interface to Watchdog
shasum -a256=7b92289327d6320246fad8021f23e6eb4de506db761f8f199eda02a2ed133e6f