ShellCheck rates SC2086 as info. It let rm delete two files I never named.

●1 ●19 ●78
calendar_today • schedule1 min read

SC2086 sits at info, ShellCheck's lowest default severity, and fires on every unquoted $var, so it is usually the first rule anyone disables. I built the smallest test I could: a directory holding quarterly, report.txt and quarterly report.txt, and a four-line script under set -euo pipefail:

report="quarterly report.txt"
rm $report

It deleted quarterly. It deleted report.txt. It left the one file it was asked to remove, and exited 0. rm was handed two names and both existed, so strict mode had nothing to catch.

Bash expands the unquoted variable, splits the result on whitespace, globs any * or ? against the current directory, and only then builds the argument list. rm "$report" is one argument with no globbing, and it deletes the right file.

The same bug hides in other shapes. [ $name = "root" ] with an empty $name gives test two arguments: a complaint on stderr, a false condition, and the script keeps walking. for f in $files is not flagged by ShellCheck 0.11.0 at all, and still breaks on the first name with a space.

When you do want the split, such as a flag string read from a config, use an array or a one-line # shellcheck disable=SC2086 with the reason. A repo-wide .shellcheckrc disable covers every future rm as well. And shellcheck --include=SC2086 runs it alone as a CI gate.

Every run, pasted from ShellCheck 0.11.0, is in the SC2086 deep dive on word splitting and globbing.

🔥 Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

More Posts

My 30-day log cleanup kept a file that was 30 and a half days old

BashSnippets - Oct 8

I escaped the dot correctly and sed still rewrote a file marked DO NOT CHANGE

BashSnippets - Oct 13

SEO Rates Philippines 2026: Costs & Packages | FloxoLab

floxolab - Oct 18

My Nginx Died at 2 AM and Nobody Noticed for 6 Hours. Now I Have a Watchdog Script

BashSnippets - May 21

bash ran a path that no longer existed, and exited 127

BashSnippets - Oct 21
chevron_left
3.8k Points • 98 Badges
North America • bashsnippets.xyz
68Posts
31Comments
10Connections
Linux user who got tired of Googling the same bash commands every time I sat down at a terminal. Sta... Show more

Related Jobs

View all jobs →

Commenters (This Week)

1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!