From: Chris F.A. Johnson on
On 2010-02-16, Janis Papanagnou wrote:
> Chris F.A. Johnson wrote:
>> On 2010-02-16, Janis wrote:
>>> On 16 Feb., 15:15, Hongyi Zhao <hongyi.z...(a)gmail.com> wrote:
>>>> On Tue, 16 Feb 2010 05:25:55 -0800 (PST), Janis
>>>>
>>>> <janis_papanag...(a)hotmail.com> wrote:
>>>>> $ grep '[ \t]' <<< $'\v' | od -c
>>>>> 0000000
>>>>> $ grep '[[:space:]]' <<< $'\v' | od -c
>>>>> 0000000 ?\v ?\n
>>>>> 0000002
>>>> Excellent examples but obscure for newbie like me to figure out its
>>>> meaning, especially the latter part of your codes: <<< $'\v' | od -c.
>>> The part
>>>
>>> CMD <<< STRING
>>>
>>> is similar to the ancient but often used
>>>
>>> echo STRING | CMD
>>
>> It's a non-portable equivalent of the standards-compliant here document:
>
> ...of the (for the given purpose) unnecessary bulky standards-compliant
> here document. Yes.
>
>>
>> CMD <<EOF
>> STRING
>> EOF
>>
>>> The $'\CHAR' is used to express control characters \CHAR, like \n for
>>> newline or \t for tab.
>>
>> But it's not standard.
>
> To make it clear, if not apparent; the above posted code is a terse
> frame (that is supported in the modern shells, BTW)

s/modern shells/some modern shells/

It is not supported by dash, for example.


--
Chris F.A. Johnson, author <http://shell.cfajohnson.com/>
===================================================================
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
===== My code in this post, if any, assumes the POSIX locale =====
===== and is released under the GNU General Public Licence =====
From: Sven Mascheck on
Chris F.A. Johnson wrote:

>> that is supported in the modern shells, BTW
>
> It is not supported by dash, for example.

ksh88, too.
From: Janis Papanagnou on
Sven Mascheck wrote:
> Chris F.A. Johnson wrote:
>
>>> that is supported in the modern shells, BTW
>> It is not supported by dash, for example.

Yes. Still besides the point, though:

>>>to *demonstrate*
>>>the _character classes compared to a list of characters_. No less,
>>>and no more.

>
> ksh88, too.

csh, too. So what?

Janis
From: Sven Mascheck on
Janis Papanagnou wrote:
> Sven Mascheck wrote:

>> ksh88, too.
>
> csh, too. So what?

It's just different, local topics. Here: what shells
concerning standard or portability know that feature.

Na paranoia, please :)
From: Geoff Clare on
Hongyi Zhao wrote:

> Hi all,
>
> What's the differences between [[:space:]] and [ \t ] when using both
> in regex pattern?

In most standard POSIX/UNIX utilities:

[[:space:]] matches a whitespace character

[ \t] matches a space, backslash or 't' character

Exceptions are awk and lex, which do backslash processing before
looking for bracket expressions.

Some implementations of POSIX utilities have a default non-conforming
mode in which backslash is recognised inside bracket expressions.
Most of the earlier posts in this thread seem to about these
non-conforming behaviours. One example is GNU sed:

$ unset POSIXLY_CORRECT
$ printf 'a\tb\nt\n' | sed -n '/[\t]/p'
a b
$ printf 'a\tb\nt\n' | POSIXLY_CORRECT=1 sed -n '/[\t]/p'
t

--
Geoff Clare <netnews(a)gclare.org.uk>