Live data from Hacker News

Start all of your commands with a comma (2009)

rhodesmill.org

71–80 of 177 posts

Re: Start all of your commands with a comma (2009)

#71

> The lower-case letters are the very characters used in system commands; brackets, backslashes, the colon, the back-tick, and the single-tick all had a special meaning to the shell Please note that brackets have no special meaning to the shell.

Brackets are used in shell wildcard ("glob") expressions. For example, if you try to use "[bar]" as a command, the shell will first look for files named "b", "a", and "r" in the current directory, and if it finds any it'll use the first one as the command name and any others as arguments to it.

But as far as I can see, using a close-bracket as the first character in a command is safe, since it cannot be treated as part of such a pattern. Open-bracket (without a matching close-bracket) would work in many shells, but will get you a "bad pattern" error in zsh.

Re: Start all of your commands with a comma (2009)

#72
post #67

Discussed in 2020: https://news.ycombinator.com/item?id=22778988 (90 comments)

Thanks!

, macroexpand:

Start all of your commands with a comma (2009) - https://news.ycombinator.com/item?id=31846902 - June 2022 (121 comments)

Start all of your commands with a comma (2009) - https://news.ycombinator.com/item?id=22778988 - April 2020 (89 comments)

Re: Start all of your commands with a comma (2009)

#74
Doesn't work with powershell (which, to be fair, was quite new at the time this blog post was released).

But honestly, while 2 or 3-letters aliases are tricky, I've very rarely had issues with 4-letter aliases. There are 456k possibilities. On my small opensuse install, my PATH contains only 105 4-letter executables.

Re: Start all of your commands with a comma (2009)

#75
post #72
post #67

Discussed in 2020: https://news.ycombinator.com/item?id=22778988 (90 comments)

Thanks! , macroexpand: Start all of your commands with a comma (2009) - https://news.ycombinator.com/item?id=31846902 - June 2022 (121 comments) Start all of your commands with a comma (2009) - https://news.ycombinator.com/item?id=22778988 - April 2020 (89 comments)

I see what you did there...

Re: Start all of your commands with a comma (2009)

#76

I'm curious how folks manage their important local configurations, e.g. - is your ~/bin directory a git repo? - if you git to manage your dot files, do you use hard links or soft links?

I got this from an old HN comment I can't find anymore. I have this in my .bashrc:

  alias dotfiles='git --git-dir=$HOME/.dotfiles --work-tree=$HOME'
And I init my dotfiles into a fresh home directory like this:

  git clone --bare gitolite3@example.com:dotfiles $HOME/.dotfiles
  git --git-dir=$HOME/.dotfiles --work-tree=$HOME config status.showUntrackedFiles no
  git --git-dir=$HOME/.dotfiles --work-tree=$HOME reset --hard

Re: Start all of your commands with a comma (2009)

#78
post #19

Earlier quoted context omitted.

But then you start using some tool that expects $0 in the system path and breaks causing frustration and debugging. Pick your poison

Fair point. I've been doing this for years and none of my scripts have ever caused any (noticeable) breakage, though. The danger is also mitigated because I only modify my own user's shell rc file. Any daemons running as root or their own user are unaffected.

Article is from 2009. Plenty of prevalent short named tools have been released since then, causing exactly this sort of issues. Just thinking about it, "node" and "npm" come to mind.

Re: Start all of your commands with a comma (2009)

#79
post #56
post #34

Earlier quoted context omitted.

> then you have to add a shebang line directly to the script itself, which I always feel uncomfortable since it's hard-coded (what if in future I don't want to execute my .py script with `/usr/bin/python` but `/usr/bin/nohtyp`?) > But I really, really just want to run `hello` to call a `hello.py` script that is in my $PATH. On Linux I'd say the shebang is still the right tool for this. If you want a lightweight appro…

> /usr/bin/env is already an abstraction). Isn't that path and the behavior of the binary defined by POSIX though? I thought it's as stable as you can get. That's why it's usually recommended that you use /use/bin/env bash vs /bin/bash in the shebang, as the latter isn't defined by POSIX

Yes, env is an abstraction for the sake of portability, but if you're setting up custom indirections then portability probably isn't much of a concern.

Re: Start all of your commands with a comma (2009)

#80
An alternative method for avoiding collisions in PATH is to use really long executable names that are unlikely to be used by other executables and then have shorter aliases for them in your bashrc. The aliases won't affect executables called from within scripts and you can still refer to your executables by their long names in your own scripts.

One drawback is that this doesn't have the same tab completion ergonomics, which I have to admit is really nifty.

EDIT: And another is that collisions can still occur in scripts that need to be sourced rather than executed as a sub-process (like Python's venv activation scripts). But those are rare.

Post reply on HN