How Safe is TOO Safe? | Spot the Error in This Shell Script Part 1

Опубликовано: 14 Май 2026
на канале: Don't Use This Code • James Powell
96
6

Is this shell script going to rm -rf my entire home directory? I don't know if I'm doing something wrong… do you?

Join the DUTC Discord Server:   / discord  
Sign up for DUTC Weekly: https://mailchi.mp/dutc/ytweekly

LinkedIn:   / do-n-t-use-this-code  
Website: https://www.dontusethiscode.com/index...
Upcoming events: learning.dutc.io
Looking for training? Contact [email protected]

This is part of the Spot the Error in This Shell Script series.

Can you spot the error in this shell script?

Join us on a bug hunting journey, designed to help you identify common pitfalls, edge-cases, and anti-patterns when writing and maintaining shell scripts. These mistakes will transcend those solved by simply putting quotes around everything, and instead point to deeper conceptual and knowledge gaps when working from the command line.

Abstract
In this series, we will try to spot some errors in Shell scripts that may lead to serious production issues (or just embarrass you by breaking for simple reasons.)

Each section will start with a shell script containing one or more (obvious) errors, then present a solution to these, as well as an in-depth discussion of the background concepts and knowledge necessary to never make this mistake again.

In this series, we'll see bugs about…

improperly operating on filenames (and failing to disambiguate in-band encodings fundamental to the command line)
failing to work around limitations of your shell (where the Python approach might have been easier)
failing to clean-up after yourself by handling child processes correctly (a hard problem to solve in general)
mistakes when trying to connect tools together using the various redirection mechanisms available
failing to come to terms with long-standing, fundamental issues with the shell (e.g., failing to deal with quoting properly)