# 别让波浪号在 PATH 中误导你

Original title: Don't Put Tilde In Your Path

> Hacker News story 50042425 · language: zh · submitted 2026-10-11
> Web version: https://zeli.app/zh/story/50042425
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 247 · by [arusekk](<https://news.ycombinator.com/user?id=arusekk>) · 💬 176
[original](<https://disconnect3d.pl//2026/10/02/dont-put-tilde-in-your-path/>) · [HN discussion](<https://news.ycombinator.com/item?id=50042425>)

## Summary

我在测试 nono 沙箱工具时，发现它警告 PATH 中存在可写入的条目：~/.local/bin/。这看似无害，实则暗藏玄机。在 ~/.bashrc 或 ~/.zshrc 中，若将 PATH 设置为 export PATH="$PATH:~/.local/bin/"，波浪号 ~ 并不会被扩展为 $HOME，而是被当作字面字符处理，导致路径变为 ./~/.local/bin/。这意味着程序可能从当前目录下的 ./~/ 文件夹中执行，而非真正的家目录。这不仅是 Bash 的语法陷阱，更是潜在的安全隐患。建议立即检查你的 PATH 配置，将所有 ~ 替换为 $HOME，确保路径解析正确。

## Key quote

> 在变量赋值中，波浪号只有在未加引号且紧跟等号或冒号时才会被正确扩展为家目录路径。

---

## Cite

- Page: https://zeli.app/zh/story/50042425
- Date: 2026-10-11
- Source: disconnect3d.pl (https://disconnect3d.pl//2026/10/02/dont-put-tilde-in-your-path/)
- Hacker News: https://news.ycombinator.com/item?id=50042425

## Other languages

- en: https://zeli.app/story/50042425 · markdown: https://zeli.app/story/50042425.md
- ja: https://zeli.app/ja/story/50042425 · markdown: https://zeli.app/ja/story/50042425.md
- ko: https://zeli.app/ko/story/50042425 · markdown: https://zeli.app/ko/story/50042425.md
- de: https://zeli.app/de/story/50042425 · markdown: https://zeli.app/de/story/50042425.md
- es: https://zeli.app/es/story/50042425 · markdown: https://zeli.app/es/story/50042425.md
- ru: https://zeli.app/ru/story/50042425 · markdown: https://zeli.app/ru/story/50042425.md
