[SOLVED] Shell glob element [:space:] not working as expected
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.