Shell
Pipes, xargs, jq and the tools that glue programs together.
The course
Open the courseStart at 01. The first lesson names the types. The next one builds an object. Each sample is on the page.
-
Skill
Basics
The types, explained, then an object you can name and call.
-
01
Shell from zero: a variable holds text
Start here
A shell variable holds text. item=latte stores latte, and echo prints it. There are no spaces around the equals sign.
Adds The types this course uses
-
02
Shell from zero: quote the expansion
A value with a space splits into two words if you leave the quotes off. "$name" keeps it one value. The program prints oat latte.
Adds An object you can name and call
-
01
Shell from zero: a variable holds text
Start here
-
Practice
Tips
A rule that prevents a bug, then a program that uses the object.
-
03
Shell from zero: a number is still text until you ask
A variable that looks like a number is text. $((cents * 2)) evaluates it as arithmetic. The program stores 450 and prints 900.
Adds A tip that prevents a bug
-
04
Shell from zero: a function is the reusable piece
A function packages a command you want to repeat. label prints a drink and its price. The program prints latte $4.50.
Adds A program that uses the object
-
03
Shell from zero: a number is still text until you ask
-
Further
A whole program
One more idea, then a program that puts the pieces together.
-
05
Shell from zero: local keeps the name inside
local makes a variable private to the function. The function prints muffin. The script then prints latte. The caller's drink is unchanged.
Adds A program that puts the pieces together
-
06
Shell from zero: read the exit code
A command returns a number when it finishes. 0 means it worked. An empty drink name fails test -n. The program prints 1. Check the code before you trust the result.
Adds A program that puts the pieces together
-
05
Shell from zero: local keeps the name inside
GoByte Skills: Shell commands track, 3 lessons. Pipes, xargs and jq: small programs composed into fast pipelines.
Open the Shell commands trackArticles
RSS-
jq: a pipeline for JSON
GoByte Skills #24: in jq, bob does not become null. He stops existing. select emits nothing for a miss, because every jq filter takes JSON in and emits a stream of zero or more values, and | runs the next step once per value.
-
xargs -P: parallelism in one flag
GoByte Skills #23: xargs -P turns a serial loop into a worker pool. Twelve seconds of jobs finish in three. Also: the missing -n that makes -P do nothing at all.
-
Pipes: the concurrency model you already use
GoByte Skills #22: a pipeline is every stage running at once, joined by 64 KiB buffers. awk streams in 1.6 MB. sort cannot: on a 444 MB log it held 2.1 GB. So filter first.