Hacker News new | past | comments | ask | show | jobs | submit login

> 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.


Brackets have a special meaning in the UNIX shell since the earliest times.

Together with "*" and "?", the brackets "[" and "]" have been used by the UNIX shell since some of its earliest versions (already many years before the Bourne shell) in pattern matching for pathname expansion (globbing).

For example, if you have in a directory 3 files named "file1", "file2" and "file3", then

"ls file?" will output

file1 file2 file3

while "ls file[13]" will output

file1 file3


Yes, of course I was too quick: I was trying to suggest to use a single bracket char in the command just as TFA uses the comma. But it turned out that an opening bracket wouldn't work with some non-bash shells. So I was doubly wrong.



Cunningham's Law in action lol




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: