Skip to content

Instantly share code, notes, and snippets.

@jjdonson
Last active August 29, 2023 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjdonson/8a5a57bb2a5e5d12c4c22817df26474f to your computer and use it in GitHub Desktop.
Save jjdonson/8a5a57bb2a5e5d12c4c22817df26474f to your computer and use it in GitHub Desktop.
open-source-dev-using-bash

Open Source Dev Using Bash3


Table of Contents


Bash Dev PDF

PDF Topics Tree

  • Syntax + Tools

  • Simple Calculations:

    • bash $ SUM=$(( VAR2+VAR1 ))
    • bash $ DIFFERENCE=$(( VAR2-VAR1 ))
    • bash $ PRODUCT=$(( VAR1*VAR2 ))
    • bash $ QUOTIENT=$(( VAR1/VAR2 ))
  • Errors:

    • Class: errorsSyntax
    • Class: errorsType
    • Class: errorsValue
    • Class: errorsPattern
    • Class: errorsHandler
    • Class: errorsLogger
    • Tests propagate towards --debug by raising errors that get handled.
    • Result Codes = 0,1,2: bash LAST_RESULT_CODE=$?
    • Simplest AND: bash $ $CMD1 && $CMD2
    • Simplest OR: bash $ $CMD1 || $CMD2
    • https://unix.stackexchange.com/questions/128005/xor-of-a-shell-variable-and-a-binary-file - Bash XOR ~ |||: bash $ $CMD1 && echo 1 ||| $CMD2 && echo 2
    • Parentheses Make Complex Logic Explicit: bash $ ( $CMD1a && CMD1b ) || ($CMD2a && $CMD2b)
    • input+output tests: tryCatchFnally() { ;}
  • Logical Operators + Shell Expansion

  • basics:

    • case
    • if
    • test
  • bash file test operators: [ -x $FILE_NAME ]

    • a
    • b
    • c
    • d
    • e
    • f
    • g
    • h
    • k
    • p
    • r
    • s
    • t
    • u
    • w
    • x
    • G
    • $ [ -L fileA ]:
    • $ [ -N fileA ]:
    • $ [ -O fileA ]:
    • $ [ -S fileA ]:
    • $ fileA -ef fileB: True when fileA and fileB refer to same device and inode numbers.
    • $ fileA -nt fileB: True when fileA newer than fileB.
    • $ fileA -ot fileB: True when fileA older than fileB.
  • Loops

    • for
    • while

Command Syntax

  • prompts: $ #
  • subcommands: $ CMD SUBCMD
  • options: $ CMD --help
  • arguments: $ CMD --file
  • parameters: $ CMD --file=ascii.txt
  • flags: $ CMD
  • defaults:
  • statement syntax

Functions

Contexts

Actions

  • cmd < input > output
  • try-catch
  • while...
  • man xargs

Hands-On Bash Dev

Prerequisites

Primative Data Types

  • Text: strings

    • Sample Text Data Operations: concatenate <|> split
  • Numbers: integers + bits + bytes

    • Sample Numeric Data Operations: maths
  • Temporal: dates + times

    • Sample Temporal Data Operations: date_diff()
  • Custom data type primatives: (x,y)

    • Sample Custom Data Operation: graphPoint(x,y)

Simple Data Type Structures

  • ascii symbols: $ # <|>

  • 2d locus: x,y

  • lists: x,y,z

  • seqs: $ NUMS_TO_100=$( seq 100 )

  • stacks:

  • arrays: matrices from homogenous and heterogenous arrays via conjugations

    • MATRIX_VAR_NAMES_ARRAY=( ?? )
    • MATRIX_PAGE_CONFIGS=( aspectRatio humanLanguage )
    • MATRIX_FIGURE_CONFIGS=( type title [ bitmap | vector ] )
    • MATRIX_CONFIGS=( quadrant axis1 axis2 legend )
    • MATRIX_AXIS_CONFIGS=( name units xyzn )
    • MATRIX_AXIS_LABEL_CONFIGS=( font color location )
    • MATRIX_AXIS_??=( )
  • dicts

Advanced Data Type Structures

  • enums with default values

    • declare -a HUMAN_LANGUAGES_ARRAY=( en es fr ja he ?? ); HUMAN_LANG_DEFAULT='en'
    • Bools default to False until True.
    • No errors in bash ( RC = 0 ) are successes.
    • Errors in bash ( RC > 0 ) are failures. They can be handled so as not to abort.
    • Test runs default to Failed until Passed. Options include: ( fail pass incomplete )
  • sets with null default

    • declare -a STATES_ZIPS_NESTED_ARRAY=( '' STATES ZIPS ); DEFAULT=''
  • baselines

    • high water marks
  • https://stackoverflow.com/questions/10730066/bash-memory-usage?rq=3

Complex Data Type Structures

  • itertoolz: generators parsers iterators

  • repositories

  • targets:

  • spectra

  • timelines:

  • cycles:

  • graphs:

  • matrices:

  • trees: [un]flatten()

  • chains: chars >-- strings >-- lines >-- files >-- directories >-- volumes

  • translations:

  • taxonomies:

  • diagrams:

  • colors

  • notes

  • beats

Symbols

  • ⊂ is a subset of
  • ⊆ is a proper subset of
  • ⊃ is a superset of

Associations Between Data Structures

  • reverse: <|>
  • one-to-many: --<
  • many-to-one: >--
  • class-types: --E
  • types-class: ∃--

Deferred Topics

  • Clusters >--< Services
  • Deployments
  • Comparing Linux shells.
  • Compare bash to PowerShell
  • Comparing bash3x vs bash 4x.
  • Test driven demos of bash builtins
  • Other linux tools like git.
  • How to compare and test programming languages.
  • Linux Cluster and System Administration
  • Linux Cluster and System Engineering

References For Bash Dev

$ bash --version                           # Print Bash Version Info
$ man bash | col -b > bash3-manual.txt     # Output Man Bash Page To Readable Text File
  • Bash Functions Support Code Reuse...
$ f_getBinaryVersion() { ${1} --version || ${1} version ; }
$ f_manTxt() { man ${1} | col -b > linux-${1}-manual.txt ; }

bash dev function libs tag tree - wip

  • Function Tag Tree: [ forests --< trees --< branches --< leaves ] | [ families --< ]
    • Ideally we ?? generate mkdir -p statement argstrings. Then we split code into scripts.

Ideas From

SeqEdu: func tag family name and descendant specifiers

  • 0: datatypes::[ logical | physical ]::[ ascii | binary ]::[ primative | advanced | complex ]::[ ?? ]

  • 1: processes::[ input | output ]

  • 2: errors

  • 3: testing

  • 4: templating::engines::[ heredoc | jinja2 ]::[ Targets --E ]

  • 5: logging::[ configs::parsers ]

  • 6: functions

  • 7: maths

  • 8: registries --E

  • 9: docs::i18n::english_US

  • 9: systems::[ hardware | software ]::linux-flavor-distro-version::[users binaries tools versions namespaces]

  • data types::strings::execs

    • character sets
    • characters collations
    • unicode
    • syntax
    • grammar
    • reserved words
    • special characters
    • special variables
    • commands
    • options
    • arguments
    • parameters
    • flags
    • statements
    • files
    • modules
    • packages
    • translations
    • docs

sys admin tree - wip

  • networks
    • subnets
  • systems::distros::flabors::versions
  • machines::[ physical | virtual ]
    • storage
    • computes
    • memory
    • nics
  • clusters
  • access::local::[ stationary | mobile ]
  • access::remote::[ lan | wan ]
    • boot
    • grub
    • enable keys
    • users
    • groups
    • roles
    • sso
  • tools
  • languages::[ human::dialects | dev::versions ]
  • tests
  • docs

Template Temple: tplTemple

  • tplTargets
  • tplGenCodes
  • tplGenTests
  • tplRegFarms
  • tplAbstractions

Template Target Types

  • documents --E
  • pdfs + XML ??
  • code files --E
  • data files --E
  • config files --E

Template Target File Naming Standards

  • markdown
  • heredoc
  • xargs
  • curl
  • j2cli
  • github actions
  • setuptools
  • ascii data file types: ini toml csv xml yaml json bash-array py-list
  • bash-{stmts,blocks,functions,scripts,profiles,rcs)
  • j2cli-stmts
  • ansible-{confs,invs,playbooks,logs)
  • vagrant
  • docker
  • tests-*
  • python3-stmts

Registry Types

  • functions
  • pages
  • repos
  • docs

Testing Tree

  • functions
  • templates
  • languages
  • frameworks
  • types
  • outputs
  • inputs::scrape::parse
  • data models
  • controllers
  • user interface widgets
  • logic
  • scale
  • security

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment