LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Shell glob element [:space:] not working as expected (https://www.linuxquestions.org/questions/programming-9/shell-glob-element-%5B-space-%5D-not-working-as-expected-742686/)

catkin 07-25-2009 05:01 AM

Shell glob element [:space:] not working as expected
 
Hello :)

The following terminal transcript shows [:space:] not matching a space character as expected. Why not?
Code:

c@CW8:~$ touch 'a b'
c@CW8:~$ ls -l a[:space:]b
ls: cannot access a[:space:]b: No such file or directory
c@CW8:~$ ls -l a*b
-rw-r--r-- 1 c c 0 2009-07-25 15:19 a b
c@CW8:~$ shopt extglob
extglob                on
c@CW8:~$ locale
LANG=en_IN
LC_CTYPE="en_IN"
LC_NUMERIC="en_IN"
LC_TIME="en_IN"
LC_COLLATE="en_IN"
LC_MONETARY="en_IN"
LC_MESSAGES="en_IN"
LC_PAPER="en_IN"
LC_NAME="en_IN"
LC_ADDRESS="en_IN"
LC_TELEPHONE="en_IN"
LC_MEASUREMENT="en_IN"
LC_IDENTIFICATION="en_IN"
LC_ALL=
c@CW8:~$ echo $SHELL
/bin/bash
c@CW8:~$ /bin/bash --version
GNU bash, version 3.2.39(1)-release (i486-pc-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.

Best

Charles

colucix 07-25-2009 05:14 AM

I have always used it with double square brackets, that is a range of characters, where the characters are those given by [:space:]. It works for me:
Code:

$ touch 'a b'
$ ls -l a[[:space:]]b
-rw-r--r-- 1 colucix users 0 Jul 25 12:09 a b
$ shopt extglob
extglob        off
$ bash --version
GNU bash, version 3.2.25(1)-release (i686-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.


catkin 07-25-2009 06:11 AM

Hello colucix
Quote:

Originally Posted by colucix (Post 3619720)
I have always used it with double square brackets, that is a range of characters, where the characters are those given by [:space:]

Thanks, that does it!

So where the GNU bash reference says Within ‘[’ and ‘]’, character classes can be specified using the syntax [:class:], where class is one of the following classes defined in the posix standard: alnum, alpha, ascii, blank ... it means [:blank:] within [] giving [[:blank:]. Good to know.

Best

Charles


All times are GMT -5. The time now is 12:29 AM.