My New Hugo Site

  1. Bash
    1. Filters
      1. grep
      2. Sed
      3. jq
    2. Shellspec
  2. Design
  3. Architectural Patterns
    1. Systemd
    2. Message Broker
    3. JSON-RPC
  4. Go
    1. Concurrency
    2. Web Applications
    3. Compound Data
    4. Json
    5. Go vs Erlang
  5. Prolog Cookbook
  6. Documentation
    1. Hugo
      1. Go Html Template
      2. Table of Contents
    2. HTML
    3. CSS
      1. Color
      2. Style Guides
      3. Layout
    4. Mathjax
  7. Visualization
    1. D3
      1. Venn Diagrams
    2. SVG
    3. Visjs
      1. Network
  8. Data
    1. Yaml
    2. Events
      1. JSON-LD
    3. JSON
      1. jCal
    4. SQL
  9. JavaScript

Bash

Bash

https://dwheeler.com/essays/filenames-in-shell.html

GNU Core Utilities

util-linux

Style guide

shfmt

Debugging tips

Commands I didn’t know

Navigation shortcuts

Manual

ShellCheck Wiki

Tutorial

BashGuide

Bashisms

nixCraft tutorials

Useless Use of Cat Award

echo vs «<, or Useless Use of echo in Bash Award?

  1. Understanding Bash
  2. Advanced Bash-Scripting Guide

TDD frameworks

Extended test command

[[ ]]

All about {Curly Braces} in Bash

returns a value in variable $? where, conversely to the norm, 0 is true and anything else false.

Shell Parameter Expansion

linuxhint

opensource

tecadmin

String content of variable

${var}

Substring

${parameter:offset:length}

Eg first 4 characters

${var:0:4}

Length of string in variable

${#var}

Search and Replace

Note pattern is a glob, not a regular expression.

${parameter/pattern/string}

The above is akin to sed 's/pattern/string/' <<<"$parameter" in that it replaces the first occurence of pattern with string.

${parameter//pattern/string}

The above is akin to sed 's/pattern/string/g' <<<"$parameter" in that it replaces all occurences of pattern with string.

${parameter/#pattern/string}

The prefix must be pattern.

${parameter/%pattern/string}

The suffix must be pattern, handy for changing filename endings.

Here Strings

COMMAND <<< $WORD

Instead of

echo $WORD | COMMAND

Coreutils

https://www.gnu.org/software/coreutils/manual/html_node/index.html

https://github.com/step-/JSON.awk

tar

Manual

Packing:

tar -cvjf seatavern.tar.bz2 seatavern

Unpacking:

tar -xvjf seatavern.tar.bz2

tr

sed

GNU Manual

Difference Between grep, sed, and awk

Regular Expressions with SED

hq

https://github.com/coderobe/hq

curl -sSL https://www.quicket.co.za/events/1 | hq '[type="application/ld+json"]' text > quicket1.json

jq

https://stedolan.github.io/jq/

How To Transform JSON Data with jq

Pretty print a json file

jq '.' example.json

Create

Retrieve

Update

Delete

List

First item

jq '.[0]' example.json
less example.json | jq '.[2] | 
  {name: .name, url: .url, startDate: .startDate, 
   venue: .location.name, region: .location.address.addressRegion}' 

https://github.com/itchyny/gojq

wget

Manual

Download a Directory and Subdirectories Using wget

Awk

Manual

In awk, the ‘^’ and ‘$’ anchor metacharacters match the beginning and end of a string, and not the beginning and end of a line.

Startup

BEGIN { action }

BEGIN    { IGNORECASE = 1 }

Cleanup

END { action }

END {
    close(curfile)          # close the last one
    for (f in filelist)     # close all the rest
        close(f)
}

Records

FNR the number of records that have been read so far from the current input file

NR the total number of input records read so far from all data files

RS record separator, default newline

RT term that matched RS

ORS output field separator

Fields

$1 first field, $2 second field…

FS field separator, default whitespace

OFS output field separator

Tools

https://github.com/koalaman/shellcheck

Date manipulation

+FORMAT

How to add days to date and get new date on Linux

https://www.shell-tips.com/linux/how-to-format-date-and-time-in-linux-macos-and-bash/#gsc.tab=0

String manipulation

https://tldp.org/LDP/abs/html/string-manipulation.html

https://earthly.dev/blog/bash-string/