
gnuWorldOrder_13x12
About this episode
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](https://www.gnu.org/software/libc/manual/html_node/Example-of-Getopt.html)
A great article about the `eval` and `set` on [Linux Journal](https://www.linuxjournal.com/content/bash-preserving-whitespace-using-set-and-eval)
[Watchdog daemon](http://www.sat.dundee.ac.uk/psc/watchdog/watchdog-testing.html)
[Systemd interface to Watchdog](http://0pointer.de/blog/projects/watchdog.html)
shasum -a256=4f760557e34dcaf6e9c4e2f73c6602b1c054debe584cea890953279d334174a6
More from GNU World Order Linux Cast
nethack from the y software set of Slackware Linux. Also, this is the final episode of the show. Thanks for a decade of support and friendship. shasum -a256=651b53e545c6a2992a5eaa8a306058dba6f5f826ac9…
strfile , fortune , adventure , arithmetic , atc , backgammon and teachgammon , banner , battlestar , bcd and morse and ppt , caesar and rot13 , canfield , countmail , cribbage , dab , factor , gofish…
thunar , thunar-volman , tumbler , xfce4-appfinder , xfce4-clipman-plugin , xfce4-dev-tools , xfce4-notifyd , xfce4-panel , xfce4-panel-profiles , xfce4-power-manager , xfce4-pulseaudio-plugin , xfce4…
xlockmore , xmms , xpaint , xpdf , xsane , xscreensaver , xsnow , Greybird , elementary-xfce , exo , garcon , libxfce4ui , libxfce4util , mousepad software set of Slackware Linux. shasum -a256=d528910…
seamonkey , seyon , ssr , vim-gvim , windowmaker , x11-ssh-askpass , x3270 , xaos , xgames , xine-lib , xine-ui from the xap software set of Slackware Linux. shasum -a256=93c563d8660d95141f9c811068ae4…