[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: help with dash manual page needed



Andrej Shadura wrote:
> I’m curious if someone here could suggest a better way to describe
> the following. 

It's really hard to define this sort of thing in a way that's both
rigorous and reader-friendly, and it needs even more work to fit such
a definition into the existing context of a document that also needs
to define other sets of escapable special characters and other kinds
of string expansion.

> Thanks in advance :)
> 
> # Shell Patterns
> 
> A pattern consists of normal characters, which match themselves, and
> meta-characters.  The meta-characters are “!”, “*”, “?”, and “[”.
> These characters lose their special meanings if they are quoted.  When
> command or variable substitution is performed and the dollar sign or
> back quotes are not double quoted, the value of the variable or the
> output of the command is scanned for these characters and they are
> turned into meta-characters.      

This makes me ask what happens in variable substitions if the dollar
sign *is* double-quoted.  The answer of course is that it wouldn't be
a variable substitution at all.
	$ echo "$"USER
	$USER

Also, "turned into meta-characters" seems vaguely misleading.  What's
happening is that dash is applying a file-globbing stage, where some
characters are treated specially.  Quoting the whole thing is just one
way of escaping them, and even when they aren't escaped they may come
out the other end of the globbing as themselves ("Foo=[!; echo $Foo").

> An asterisk (“*”) matches any string of characters.  A question mark
> matches any single character.  A left bracket (“[”) introduces a
> character class.  The end of the character class is indicated by a
> (“]”); if the “]” is missing then the “[” matches a “[” rather than
  ^   ^
Either excess parentheses or a missing reference to "right bracket".

> introducing a character class.  A character class matches any of the
> characters between the square brackets.  A range of characters may be
> specified using a minus sign.  The character class may be complemented
> by making an exclamation point the first character of the character
> class.         

Character name pedantry: Unicode says it's 0x002D HYPHEN-MINUS, 0x2212
MINUS SIGN, 0x2010 HYPHEN.  Of course, the reason hyphen-minus is used
for ranges is that the character also serves as the ASCII stand-in for
0x2013 EN DASH, but calling it a dash would just make the dash manual
page more confusing.

> To include a “]” in a character class, make it the first character
> listed (after the “!”, if any).  To include a minus sign, make it
> the first or last character listed.

You don't mention how to escape [ and !; maybe it could generalise:

  Characters that are special within character classes are treated as
  non-special if placed where the special interpretation is not
  possible: a "]" at the beginning of the list (after any "!"), a
  hyphen-minus at beginning or end, and so on.
-- 
JBR	with qualifications in linguistics, experience as a Debian
	sysadmin, and probably no clue about this particular package


Reply to: