Pipes and capture
In the terminalela --spec pipes-and-capture
- Pipes use
|as in Bash:ls | grep amber. - Capture with
$(...):files = $(ls). The trailing newline is trimmed. - A pipeline fails if any stage fails (
pipefailby default), with the code of the last stage that failed. |is strict: a stage stopped because the next one stopped reading (SIGPIPE, exit code 141) has failed too, since nothing but the script's own text says whether that stage had work left.|?is the lenient pipe: the stage before it may be stopped that way. Any other failure of that stage still fails the pipeline.
last = $(sort -r server.log |? head -1) # sort has nothing left that mattersrsync -a /home/ backup.example:/srv/home/ | head # a cut-off rsync is half a backup: an error