<h1 id="today-i-learnt-more-bash-tips">Today I Learnt more Bash
tips</h1>
<h2 id="sgoti-talks-about-supplying-options-to-bash-scripts">Sgoti talks
about supplying options to bash scripts</h2>
<ul>
<li>Tags: Bash tips, TIL, getopts</li>
</ul>
<pre class="bash"><code>#!/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 &lt;https://www.gnu.org/licenses/&gt;.

#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} &lt;&lt; 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 &quot;:s:r:q:h&quot; option; do
    case $option in
        s)
        show=$OPTARG

function mkq () {
    ${mkdir} -v -p ${dirqueue}/${show}/edit;
    ${mkdir} -v -p ${dirqueue}/${show}/prod;
    ${cat} &gt; ${dirqueue}/${show}/edit/${show}.md &lt;&lt; _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/ &quot;CC-BY-SA 4.0 International&quot;).

_EOD_

    builtin pushd -n ${dirqueue}/${show}/edit;
    builtin pushd -n ${dirqueue}/${show}/prod;
}

        if [ -d ${dirshow1} ]; then
            mkq
        else
            ${echo} &quot;Good Heavens! It&#39;s a new year.&quot;;
            ${mkdir} -v -p ${dirshow1};

            mkq
        fi
        ;;

        r)
        reserve=$OPTARG
function mkr () {
    ${mkdir} -v -p ${dirreserve}/${reserve}/edit;
    ${mkdir} -v -p ${dirreserve}/${reserve}/prod;
    ${cat} &gt; ${dirreserve}/${reserve}/edit/${reserve}.md &lt;&lt; _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/ &quot;CC-BY-SA 4.0 International&quot;).

_EOD_

    builtin pushd -n ${dirreserve}/${reserve}/edit;
    builtin pushd -n ${dirreserve}/${reserve}/prod;
}

        if [ -d ${dirshow1} ]; then
            mkr
        else
            ${echo} &quot;Good Heavens! It&#39;s a new year.&quot;;
            ${mkdir} -v -p ${dirshow1};

            mkr
        fi
        ;;

        q)
        ${echo} &quot;Goodbye.&quot;;
        exit
        ;;

        h)
        help
        exit
        ;;

        *)
        if [ -z &quot;${option}&quot; ]; then
            help
            exit 1
        fi

        ${echo} &quot;Good Heavens! Invalid input.&quot;;
        help
        exit
        ;;
    esac
done


exit;
</code></pre>
<pre class="bash"><code>#!/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 &lt;https://www.gnu.org/licenses/&gt;.

#Name: sc.sh
#Purpose:
#Version: beta 0.01
#Author: SGOTI (Some Guy On The Internet)
#Date: 2023-12-31

#variables:

bindir=/usr/bin/

cat=${bindir}cat
date=${bindir}date
echo=${bindir}echo
ls=${bindir}ls
screen=${bindir}screen

#start:

    ${echo} -e &quot;\nStep 0: $(${date} +%F), $(${date} +%T)&quot;;

function help() {
${cat} &lt;&lt; EOH
Usage: $0 [-b] [-s] [-k] [-h] name-of-show

    -b [y|n] (Create or kill, base sockets.)
    -s       (Create new sockets.)
    -k       (Kill sockets.)
    -h       (help menu)

Examples:
        $0 -b y
        $0 -b n
        $0 -s name-of-socket
        $0 -k name-of-socket
        $0 -h

EOH
}

    ${echo} -e &quot;\nStep 1: $(${date} +%F), $(${date} +%T)&quot;;

while getopts &quot;:b:s:k:h:&quot; option; do
    case &quot;${option}&quot; in
        b)
        userinput0=$OPTARG
        if [ ${userinput0} == &quot;y&quot; ]; then
        ${screen} -dmS apps;
        ${screen} -dmS jobby;
        ${screen} -ls;
        elif [ ${userinput0} == &quot;n&quot; ]; then
        # You don&#39;t need the entire name to kill the socket.
        ${screen} -X -S &quot;app&quot; kill
        ${screen} -X -S &quot;job&quot; kill
        ${screen} -ls;
        else
        ${echo} &quot;Good Heavens!&quot;
        ${screen} -ls;
            help
            exit 1
        fi
        ;;

        s)
        userinput0=$OPTARG
        ${screen} -dmS &quot;${userinput0}&quot;;
            clear
        ${screen} -ls;
            ${echo} -e &quot;\nNew sockets: $(${date} +%F), $(${date} +%T)&quot;;
        ;;

        k)
        userinput0=$OPTARG
        ${screen} -XS ${userinput0} kill
            clear
        ${screen} -ls;
            ${echo} -e &quot;\nKill sockets: $(${date} +%F), $(${date} +%T)&quot;;
        ;;

        h)
        help
            ${echo} -e &quot;\nHelp menu: $(${date} +%F), $(${date} +%T)&quot;;
        exit
        ;;

        *)
        if [ -z &quot;${option}&quot; ]; then
            help
            exit 1
        fi

        ${echo} &quot;Good Heavens! Invalid input.&quot;;
        help
        exit
        ;;
    esac
done

    ${echo} -e &quot;\nStep 2: $(${date} +%F), $(${date} +%T)&quot;;

exit;
</code></pre>
<ul>
<li><strong>Source:</strong> <a
href="https://hackerpublicradio.org/series/0123.html">In-Depth Series:
Today I Learnt</a></li>
<li><strong>Source:</strong> <a
href="https://hackerpublicradio.org/series/0042.html">In-Depth Series:
Bash Scripting</a></li>
</ul>
<p>This work is licensed under a <a
href="https://creativecommons.org/licenses/by-sa/4.0/"
title="CC-BY-SA 4.0 International">Creative Commons
Attribution-ShareAlike 4.0 International License</a>.</p>
