beginner
Good starting points for newcomers
-
Parameter expansion
Bash parameter expansion: default values with :-, trimming paths with # and %, replacing text with //, and slicing, length and case conversion.
-
Where a script lives
What $0 really contains, why a script cannot find a file next to itself with a relative path, and the BASH_SOURCE line that works through a symlink.
-
Arithmetic
Integer arithmetic in bash with $(( )) and (( )), -eq against =, why a leading zero is an error, and the awk one-liner for sums bash cannot do.
-
Here-docs and generating files
Here-documents in bash: feeding a block of text to a command, quoting the terminator to stop expansion, generating config files, and here-strings.
-
Traps and cleanup
The mktemp and trap EXIT pattern for scripts that clean up after themselves, why the trap body needs single quotes, and what set -e does not cover.
-
Debugging and robustness
Reading what a script actually did with bash -x and PS4, checking syntax without running it, making unset variables fatal, and what shellcheck catches.
-
A real script
A capstone backup script using arguments, arrays, parameter expansion, a trap and real exit codes, and how to schedule it with cron or a systemd timer.
-
Add a directory to your PATH permanently
How to put a directory on PATH for good on Debian, why ~/.local/bin needs no configuration at all, and what to do for any other directory.
-
Could not get lock /var/lib/dpkg/lock-frontend
apt refuses to run because something else is already installing. Modern apt tells you exactly which process, and deleting the lock file is the wrong fix.
-
The following packages have been kept back
apt-get upgrade refuses to install new packages, so an upgrade that needs one is held back instead. What the message means and the three things that cause it.
-
sudo: command not found
On Debian, sudo is often simply not installed, and your user is not in the sudo group. Why the installer does that, and how to fix it from a root shell.
-
apt vs apt-get
The same package ships both, and they do the same job. What differs is who each is written for, and only one of them is safe in a script.
-
remove vs purge vs autoremove
Not three strengths of one operation. Two of them differ over configuration files; the third acts only on packages you never asked for.
-
sh vs bash vs dash
On Debian /bin/sh is dash, not bash. That one fact explains most scripts that work at your prompt and fail the moment something else runs them.
-
which vs type vs command -v
which searches PATH and nothing else, so it reports that cd does not exist. What type and command -v answer instead, and which one belongs in a script.
-
Which package provides a file
Trace a file to the package that ships it: dpkg -S for what is installed, apt-file for what is not, and the files that belong to no package at all.