scripting
Shell scripting techniques
-
Bulk rename a batch of files
Rename many files at once with a plain bash loop, safely handling spaces and previewing changes before committing.
-
Time how long something takes
What real, user and sys actually measure, why the time you type is not /usr/bin/time, and how to capture a timing into a file instead of the terminal.
-
command not found
The shell says this for a command that is missing, one that is not on PATH, one it remembers in the wrong place, and a script whose interpreter is gone.
-
Works in the shell, fails in cron
cron hands a job five variables and a PATH of /usr/bin:/bin, runs it from your home directory under dash, and sends the failure somewhere you are not looking.
-
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.