Hacker Public Radio

HPR4088: Today I Learnt more Bash tips


Listen Later

Today I Learnt more Bash
tips
Sgoti talks
about supplying options to bash scripts
Tags: Bash tips, TIL, getopts
#!/bin/bash
# License: GPL v3
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#Name: showtime.sh
#Purpose: Time to make a show.
#Version: beta 0.01
#Author: SGOTI (Some Guy On The Internet)
#Date: 2023-12-29
#variables:
bindir=/usr/bin/
cat=${bindir}cat
date=${bindir}date
echo=${bindir}echo
mkdir=${bindir}mkdir
dirshow0=${HOME}/Music/hpr/shows
dirshow1=${dirshow0}/$(${date} +%Y)
dirqueue=${dirshow1}/queue/$(${date} +%F)
dirreserve=${dirshow1}/reserve-queue/$(${date} +%F)
#start:
function help() {
${cat} << EOH
Usage: $0 [-s] [-r] [-q] [-h] name-of-show
-s (Regular queue)
-r (Reserve queue)
-q (quit)
-h (help)
Examples:
$0 -s name-of-show
$0 -r name-of-show
$0 -q
$0 -h
EOH
}
## Use `getopts` to read user option into script. ##
while getopts ":s:r:q:h" option; do
case $option in
s)
show=$OPTARG
function mkq () {
${mkdir} -v -p ${dirqueue}/${show}/edit;
${mkdir} -v -p ${dirqueue}/${show}/prod;
${cat} > ${dirqueue}/${show}/edit/${show}.md << _EOD_
# ${show} #
## subtitle ##
- Tags:
This work is licensed under a [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/ "CC-BY-SA 4.0 International").
_EOD_
builtin pushd -n ${dirqueue}/${show}/edit;
builtin pushd -n ${dirqueue}/${show}/prod;
}
if [ -d ${dirshow1} ]; then
mkq
else
${echo} "Good Heavens! It's a new year.";
${mkdir} -v -p ${dirshow1};
mkq
fi
;;
r)
reserve=$OPTARG
function mkr () {
${mkdir} -v -p ${dirreserve}/${reserve}/edit;
${mkdir} -v -p ${dirreserve}/${reserve}/prod;
${cat} > ${dirreserve}/${reserve}/edit/${reserve}.md << _EOD_
# ${reserve} #
## subtitle ##
- Tags:
This work is licensed under a [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/ "CC-BY-SA 4.0 International").
_EOD_
builtin pushd -n ${dirreserve}/${reserve}/edit;
builtin pushd -n ${dirreserve}/${reserve}/prod;
}
if [ -d ${dirshow1} ]; then
mkr
else
${echo} "Good Heavens! It's a new year.";
${mkdir} -v -p ${dirshow1};
mkr
fi
;;
q)
${echo} "Goodbye.";
exit
;;
h)
help
exit
;;
*)
if [ -z "${option}" ]; then
help
exit 1
fi
${echo} "Good Heavens! Invalid input.";
help
exit
;;
esac
done
exit;
#!/bin/bash
# License: GPL v3
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be us
...more
View all episodesView all episodes
Download on the App Store

Hacker Public RadioBy Hacker Public Radio

  • 4.2
  • 4.2
  • 4.2
  • 4.2
  • 4.2

4.2

34 ratings


More shows like Hacker Public Radio

View all
The Changelog: Software Development, Open Source by Changelog Media

The Changelog: Software Development, Open Source

289 Listeners

Defensive Security Podcast - Malware, Hacking, Cyber Security & Infosec by Jerry Bell and Andrew Kalat

Defensive Security Podcast - Malware, Hacking, Cyber Security & Infosec

373 Listeners

LINUX Unplugged by Jupiter Broadcasting

LINUX Unplugged

268 Listeners

SANS Internet Stormcenter Daily Cyber Security Podcast (Stormcast) by Johannes B. Ullrich

SANS Internet Stormcenter Daily Cyber Security Podcast (Stormcast)

653 Listeners

Curious Cases by BBC Radio 4

Curious Cases

826 Listeners

The Strong Towns Podcast by Strong Towns

The Strong Towns Podcast

422 Listeners

Late Night Linux by The Late Night Linux Family

Late Night Linux

164 Listeners

Darknet Diaries by Jack Rhysider

Darknet Diaries

8,035 Listeners

Cybersecurity Today by Jim Love

Cybersecurity Today

181 Listeners

CISO Series Podcast by David Spark, Mike Johnson, and Andy Ellis

CISO Series Podcast

189 Listeners

TechCrunch Daily Crunch by TechCrunch

TechCrunch Daily Crunch

42 Listeners

Strict Scrutiny by Crooked Media

Strict Scrutiny

5,800 Listeners

2.5 Admins by The Late Night Linux Family

2.5 Admins

98 Listeners

Cyber Security Headlines by CISO Series

Cyber Security Headlines

139 Listeners

What the Hack? by DeleteMe

What the Hack?

221 Listeners