Semicolon & Sons
X
About
Contact & Support
Code Diary
Episodes
Blog
Subscribe
Sign in
Semicolon & Sons
About
Screencasts
Code Diary
Blog
Contact & Support
Subscribe
Sign In
Bash Code Diary Entries
This is part of the Semicolon&Sons
Code Diary
- consisting of lessons learned on the job.
Bash profile vs bashrc vs profile
Be careful not to clobber existing traps
Clis do not use commas between entries
Comments are invalid in multi line bash commands
Consider the effect on your argument numbers when a variable may not be set
Deploy scripts must be idempotent and deleting existing code folder is the simplest way to achieve this
Do not forget semicolons when running sh c
ENV variables are strings
Exiting from a subshell does not end your shell script
Here string in shell
How to check if a program is available
How to check if a shell script received any arguments
How to control flow based on booleanish variables in bash scripts
How to convert unix timestamp to human readable on command line
How to do arithmetic in bash
How to do math on the command line
How to dry up repeated flags in bash scripts using wrapper functions
How to get a remote REPL to read from STDIN pipe
How to get past developer cannot be identified restrictions on command line
How to iterate through numbers in bash
How to keep retrying some code until it works
How to parallelize a loop
How to remove first n digits in bash with string substitution
How to rename many files with string substitution
How to turn many lines into one line
How to use 100 percent CPU on all cores
Leading 0s cause bash to interpret numbers in the wrong base
List all available commands
Numbers following interpolated variables need to be in separate strings
One liner for setting exit code to numbers under your control
Remove a single sensitive entry from history
Scripting basics
Shell commands in loops compete for STDIN in unpredictable ways
Shorthand to get the last argument of the previous command
Show errors codes on screen always
Simple redirecting can include too much
Some err traps are skipped with set e
The outermost string must have double quotes for string substitution to work in nested single quote strings
Trap ERR vs trap EXIT
Understand redirection
Understand why colors disappear with pipes
Up your pipe game with the echo and command substitution trick
Use a heredoc to execute many commands remotely
Use arrays instead of strings for building up bash argument lists to pass to other commands
Use non interactive flags in scripts
Use redirection to stop programs printing out filenames in their output
Ways of iterating in bash
What does the set command do
Wildcard ignores hidden files
Worked example of a subshell
Write out full flags in reused code
You can append with redirection as well as overwrite a file
You cannot connect STDIN to interactive processes