ARG_MAX| Shells | whatshell | portability | permissions | UUOC | ancient | - | ../Various | HOME
"$@"| echo/printf | set -e | test | tty defs | tty chars |
)| IFS | using siginfo | nanosleep | line charset | locale
[...]" in Bourne shells
In traditional Bourne shells you'll find two variations about
the matching with the expression "
especially if a '
-' is contained.
The manpage usually reads like the following:
"[...] Matches any one of the enclosed characters. A pair of characters separated by - matches any character lexi- cally between the pair, inclusive."
This definition is very terse.
Neither does it mention whether it's legal to use brackets as
range delimiters, nor does it explain how to match a literal
The behaviour for the parts remaining undefined was modified with the SVR3 variant, albeit the exact behaviour even then still wasn't documented.
Why was it changed? In practice you certainly might be tempted to make usage of the undefined ways, too. And it does make sense having a state machine in mind: Matching two characters, one of them being a dash, doesn't strictly indicate a range. Also, a second opening bracket clearly may be part of a range (as ranges cannot be nested).
For robustness, you might stay with the documented (and portable) way. The following text in contrast deals with the undefined behaviour.
It's also not documented that both variants not only recognize the ranges - but the complete, literal string itself (with dash and outer brackets) will always match, too. This fact is not mentioned anymore in the following.
Here are the possible variations:
It's safe to use
[...] as this
construct cannot be nested and the shell internally only searches for the
Note that using
[ in a range is closely related with
using it literally,
[X-", as if a range were finished with
[[-x]", as if a range were started with
The next two in contrast are very ambiguous:
[X-]]", as if a range were finished with
-with a bracket appended:
-x]", as if a range were started with
-is at the beginning,
-is at the end,
So the modern variant was introduced to behave more intuitive. One might just consider it a bugfix.
What about other shells?