diff options
author | bnewbold <bnewbold@robocracy.org> | 2017-09-28 22:45:53 -0700 |
---|---|---|
committer | bnewbold <bnewbold@robocracy.org> | 2017-09-28 22:45:53 -0700 |
commit | a2f4b6ff17a51c190ea4f35bdaedc44a7f50c35e (patch) | |
tree | 88be4850c3f52ef8d8ccd715ec2336eb6865fed7 /software/bash.page | |
parent | e6edc12f06231becdaa47b6f10884d0ebf62e587 (diff) | |
download | knowledge-a2f4b6ff17a51c190ea4f35bdaedc44a7f50c35e.tar.gz knowledge-a2f4b6ff17a51c190ea4f35bdaedc44a7f50c35e.zip |
bash tutorial and notes
Diffstat (limited to 'software/bash.page')
-rw-r--r-- | software/bash.page | 53 |
1 files changed, 29 insertions, 24 deletions
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. |