From a2f4b6ff17a51c190ea4f35bdaedc44a7f50c35e Mon Sep 17 00:00:00 2001 From: bnewbold Date: Thu, 28 Sep 2017 22:45:53 -0700 Subject: bash tutorial and notes --- software/bash.page | 53 +++++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 24 deletions(-) (limited to 'software/bash.page') diff --git a/software/bash.page b/software/bash.page index 0a3f73f..088d456 100644 --- a/software/bash.page +++ b/software/bash.page @@ -1,43 +1,48 @@ --- -format: rst +format: md toc: no ... -================== BASH ================== -Job Control - The syntax for "job number" or "JOBSPEC" (when using ``kill`` or similar) is ``%4`` or ``%5``. -Startup -------- -``bash`` by default takes a very long time to initialize because the +# Tricks and Specifics + +## Job Control + +The syntax for "job number" or "JOBSPEC" (when using `kill` or similar) is +`%4` or `%5`. + + +## Startup + +`bash` by default takes a very long time to initialize because the auto-completion scripts are loaded multiple times; disable this in -``~/.bashrc``? +`~/.bashrc`? + + +## Piping -Piping ---------- -You can pipe both ``stdout`` and ``stderr`` together either to a file or two another command:: +You can pipe both `stdout` and `stderr` together either to a file or two another command:: grep --asdf >& /some/file grep --asdf |& less -Network Access ----------------- -You can directly access network sockets as if they were files from bash using -the virtual devices ``/dev/tcp/HOSTNAME/PORT`` and ``/dev/udp/HOSTNAME/PORT``. -printf ------- -The ``printf`` command is much more powerful than "echo". +## printf + +The `printf` command is much more powerful than `echo`. + -Prelude -------- +## Prelude -`set`: +I frequently add a one-line version of the following to shell scripts: - -e fail on error - -u fail if variable not set in substitution - -o pipefail fail if part of a '|' command fails + set -e # fail on error + set -u # fail if variable not set in substitution + set -o pipefail # fail if part of a '|' command fails +Note that `join`, `grep`, and others sometimes exit non-zero return codes on +purpose (eg, pipe input closed or found no matches, as expected), which makes +life difficult. Sometimes `|| true` is enough to get around this. -- cgit v1.2.3