Avoiding path anti-patterns

Some shell script programmers use absolute paths for even common system tools:

/bin/sed '/^$/d' data

This command line is intended to print the contents of the data file, but to skip blank lines. It does work on most GNU/Linux systems, but why specify the full /bin/sed path? Why not just sed?

Worse, sometimes people try to abbreviate this by saving the full paths in variables, after retrieving them with a non-standard tool such as which:

# Terrible code; never do this!
SED=$(which sed)
$SED '/^$d/' data
Can you see anything else wrong with this code? Hint: what was the very first thing we re-emphasized in this chapter?

This use of which and full paths such as this is unnecessary, and there are no advantages to ...

Get Bash Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.