Meeting-2018-08-25-Bash Scripting

So, it turns out that WordPress doesn’t like my little script, and if you want a copy of it, you’ll need to download it with;

wget https://www.clug.org/Bashy

Some days I just don’t appreciate a CMS as much as I should…


#!/bin/bash -i
# This script shows some of the features of the Bourne Again SHell
# or bash.
# It is designed to be run from a terminal as a presentation,
#
#
# Steve Jones, for the 2008-04-26 meeting, CLUG.org
# Updates and information will be made available as quickly
# as time permits.
# Edited and presented again for the 2018-08-25 meeting.
#
# Test to see if we were given a starting slide on
# the command line
if [ "$1x" = "x" ] 	# The special variable $1 is the first
then Slide=1	# argument on the command line, $2 is
else		# the second, etc... Here we check to
Slide=$1	# see if a slide number was given.
fi

# Wait for a keypress and then continue on with the script.
Wait() {
# This is a function, it is delimited by the curly brackets
# above and below. It stops at the current cursor location
# and silently waits for a keypress
read -s -n 1 Anykey
}

# Format stdin to fit nicely on the screen.
Format() {
# Another function, this one is handed input on stdin, it then
# breaks it into nice, screen width-or-less lines.
fmt --split-only --width=$COLUMNS
}

# Pause for a second
Sleep() {
read -s -n 1 -t 1 Anykey
}

# Wait for a keypress at the bottom of the screen then clear
# the screen before continuing on with the script.
Pause() {
echo -en "\033[$LINES;5H"
# Read (-s, Silently) (-n 1, Single Char) (-p, "Prompt") Variable
read -s -n 1 -p "$Slide " Anykey
}

# Set the screen for black text on a grey background.
CodeOn() {
echo -e "\033[47m\033[30m"
}

# Set the screen back to black on white.
CodeOff() {
echo -e "\033[0m"
}

# Put a title on each page and center it on the top line
Title() {
clear
EightySpaces="                                                                                "
Spaces="${EightySpaces:0:$(( ($COLUMNS/2)-$(( ${#1}/2 )) ))}"
echo "$Spaces"$1
# Okay, this needs an explanation. The EightySpaces variable is
# just what it says, eighty space characters. The next line
# assigns a substring of $EightySpaces, starting at the first
# character (0, or leftmost), and continuing for half of the
# screen width minus half of the length of the title. The
# title is handed to the function at the time of invocation.
}

S-01() {
Title "What is Bash?"
# Our first slide, it is a function that contains a number of
# functions. First is the one above, which calls the title
# function to make things pretty, then the format function below
# to make the rest prettier.