Skip to content

Instantly share code, notes, and snippets.

@gthrm
Last active December 14, 2021 08:58
Show Gist options
  • Save gthrm/ea77041ad94d777e68ce1827791ceb1d to your computer and use it in GitHub Desktop.
Save gthrm/ea77041ad94d777e68ce1827791ceb1d to your computer and use it in GitHub Desktop.
test.sh
#!/bin/bash
# Name: test.sh
# Purpose: Demos compgen and complete
# Author: Vivek Gite, under GPL v2.x+
# ------------------------------------------
# My default interface
if_default="br0"
# Help
USAGE="usage: $0 -d -h -i -r -H"
# CLI args
# -d for date
# -h for hostname
# -i for IP address
# -r for routing
# -H get help
# -----------------------------
while getopts :dhirH opt_char
do
case $opt_char in
d)
echo "Date: $(date)"
exit;;
h)
echo "Hostname: $HOSTNAME"
exit;;
i)
echo -e "IP for $if_default interface\n $(ip addr show $if_default)\n"
exit;;
r)
echo -e "Default routing for $HOSTNAME:\n $(ip route show)\n"
exit;;
H)
echo "$USAGE"
exit;;
\?)
echo "$OPTARG is not a valid option."
echo "$USAGE"
exit;;
esac
done
echo "$USAGE"
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment