The tilde in your PATH may not be your HOME

241 points · 160 comments on HN · read original →

Points and comments are a snapshot, not live.

An unquoted tilde in PATH expands to a literal `~` directory, not $HOME.

Putting `export PATH="$PATH:~/.local/bin/"` in .bashrc or .zshrc does not expand the tilde to the home directory because tilde expansion only happens on unquoted words in Bash and Zsh. This adds `./~/.local/bin/` to PATH, which can resolve to a directory in the current working directory. The fix is to use `$HOME/.local/bin/` instead. The shell's tilde expansion does work in unquoted variable assignments after `=` or `:`, but a whitespace breaks it. The author demonstrates the issue with a test showing a binary in `./~/.local/bin/` being executed. Check your PATH with `echo "$PATH" | grep -- '~'`.

What commenters are saying

Commenters widely treat this as a known footgun: top comment calls it "Bash footgun #238503." Several note the behavior is standard POSIX, not just Bash. A split exists on directory ordering: some argue `$HOME/.local/bin/` should come first for custom overrides, others warn this lets local file writes shadow system binaries like `sudo`. Practical advice emerges: use `fish_add_path`, Zsh's `path=( ~/bin $path )`, or just avoid quoting the tilde. One commenter suggests restricting filenames to portable POSIX characters to avoid such issues.