工具与资源rhodesmill.org
让所有命令都以逗号开头(2009)
Start all of your commands with a comma (2009)
2020 — 2024,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这篇文章介绍作者的一个 shell 命名约定:给自己写的命令统一加上逗号前缀(如 `,foo`),因为常规系统命令几乎不会以逗号开头。这样能避免自定义命令与系统命令或未来安装的软件重名,也让私有命令一眼可辨。评论中还讨论了用别名、包装器和类似命名空间的做法。
为什么经久不衰:它用一个几乎零成本的命名约定解决 PATH 中的命令冲突,简单实用,多年后仍值得借鉴。
HN 评论精选
用独特文件名加别名避免冲突,并可顺便包装系统命令。
我的做法有点特别:与其把脚本命名为 foobarnator,冒着将来出现同名命令冲突的风险,我把它命名为 foobarnatorToBeAliased.sh,再用别名把 foobarnator 指向它。别名传参时需要借助函数(至少据我所知在 Bash 里如此),但一切正常。由于别名不会在其他脚本运行时被 source,我确信自己的脚本永远不会冲突。我多年来一直这样做,也适合给现有命令加包装器,比如增加输入清洗来捕获我常犯的错误。
TacticalCoder查看英文原文
I do something a bit special... Instead of naming my script foobarnator (and hence risking that another foobarnator may exist in the future and may clash with my script), I name my script foobarnatorToBeAliased.sh. Then in my list of aliases I alias foobarnator to foobarnatorToBeAliased.sh. The alias itself looks a bit weird in that to pass arguments to an aliased command you need to use a function (in Bash at least AFACIT) but it all works fine. As aliases aren't sourced when other scripts are running, I'm sure my scripts/commands ain't ever going to clash with anything. I've been doing that since years. It also works fine to add "wrappers" to existing commands: for example to add additional input sanitization catching common mistakes I'm making when calling some commands.
认为同名冲突通常无害,自定义命令优先也无妨。
如果我在不知情的情况下把自定义命令命名得和某个系统命令一样,而且它排在 PATH 前面,真的会有问题吗?反正我本来也不用那个系统命令,而且只有我的 .bashrc 先执行时,自定义命令才会优先。
Timpy查看英文原文
If I unknowingly named my command the same as some system command and the custom command ends up earlier in my path it doesn't really cause any problems does it? I wasn't using that system command anyways, and my custom command is only going to take priority if my .bashrc file was run first.
Windows 上也有类似做法:用特殊目录和前缀免改 PATH。
我在 Windows 上用过类似技巧。我想在默认窗口系统里加一个放工具库的地方,大多是从各处来的便携式 cmd 应用(sysinternals、nirsoft)。我把它们全放到驱动器根目录下一个叫 `]` 的目录里。由于常见键盘布局中 `\` 和 `]` 挨得很近,我可以在工具名前输入 `\]\`,甚至不用把目录加进 PATH。我确信这冒犯了某些人的审美,但作为顾问,遇到古怪机器而机主不想永久安装诊断工具时,这多年来节省了时间。
prosaic-hacker查看英文原文
I have used a similar windows trick. I wanted to add to the default window system a place for my library of tools. Most are "portable" cmd apps from various sources (sysinternals, nirsoft). I put them all into a directory called ] in the root of a drive. Because of some common layout of keyboards the \ and ] are near each other, or in reach of left and right pinkies I can type \]\ before the name of the tools. This means I don't even have add a dir to the path. I am sure this violates someone sensibilities but it has saved time over the years as a consultant when I had to deal with a wonky machine and owner did not want permanent install of diagnostic tools.
赞赏技巧,但希望 shell 提供真正的命令命名空间。
聪明的小技巧。可惜没有好的命令命名空间办法。如果能这样会很有意思:比如建 `/tmp/bin/my/hello`,把 `/tmp/bin` 加入 PATH,然后执行 `my/hello` 就输出 hello。
Taywee查看英文原文
Clever trick. Too bad there's no good way to namespace commands. It would be interesting if you could have, for instance: $ mkdir -p /tmp/bin/my $ printf '%s\n%s\n' '#!/bin/sh' 'echo hello' > /tmp/bin/my/hello $ chmod 755 /tmp/bin/my/hello $ PATH="/tmp/bin:$PATH" $ my/hello hello
历次讨论
同类还值得读
直接在浏览器中启动 Linux 内核
Boot a linux kernel right inside your browser.
Fabrice Bellard 的 JSLinux 页面,用 JavaScript 在浏览器里启动一个 Linux 内核,并提供一个可交互的终端环境。
工具与资源上首页 5 次 · 2011–2025bellard.orgHacker News 未公开功能与行为清单(2018)
A List of Hacker News's Undocumented Features and Behaviors (2018)
数据科学家 Max Woolf 整理的 Hacker News 未公开功能与行为清单,涵盖投票机制、排名算法、账号惩罚等社区运作细节。
工具与资源上首页 5 次 · 2019–2025github.comMapSCII:在终端中用盲文和 ASCII 渲染地图
MapSCII – Braille and ASCII map renderer for the console
MapSCII 是一个在命令行终端里渲染地图的开源工具,用盲文字符和 ASCII 字符把地理数据画成可交互浏览的字符地图。
工具与资源上首页 5 次 · 2017–2025github.com顶尖大学的免费在线课程
Free Online Courses from Top Universities
Open Culture 整理的一份免费在线课程合集,汇集了全球顶尖大学(如 MIT、斯坦福、耶鲁等)向公众开放的网络课程资源,涵盖音频、视频等多种形式。
工具与资源上首页 5 次 · 2010–2022openculture.com淘气字符串:容易引发用户输入问题的字符串清单
Naughty Strings: A list of strings likely to cause issues as user-input data
一个 GitHub 仓库,收录了大量容易让程序出问题的用户输入字符串,如特殊字符、emoji、SQL 注入片段、系统命令等,供开发者用于测试输入处理逻辑。
工具与资源上首页 4 次 · 2015–2020github.com