Jan Kundrát wrote: > Steve Long wrote: >>> Is [[:alpha:]] locale-safe? >>> >> Yes, all POSIX character classes listed here are: >> http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap07.html > > Thanks for a nice link. If I read section 7.3.1 correctly, [[:alpha:]] > always contains those letters, but might contain more, depending on the > locale. So it's probably very minor point, but as long as the script > runs with user-provided locale, one should be explicit here. Or am I > missing something here? > No, that's about the size of it-- if you you'd like to tie it to ASCII, irrespective of locale, that's fair enough. It depends on what you're up to (sorry, I don't have time to go digging through code to see what this applies to) but in the /general/ case it's better to use locale-neutral character-classes, since it makes scripts much more useful.
Setting LC_ALL=C temporarily is not a good idea, since it overrides LC_CTYPE. The most common usage for that is for sort order; where that's needed it's better to use LC_COLLATE. (man 7 locale) Quick example showing why the double-bracket appears: if [[ ${v:0:1} != [[:alpha:]_] || $v = *[^[:alnum:]_]* ]]; then errMsg $"$v is not a valid identifier" return 1 fi Getting to know these is really helpful, imo, especially since they apply to _all_ the utilities like tr, sed, grep, awk -- and ed ofc ;) $"text" is for i18n in bash via gettext, akin to _"foo" in C. Can't say I've used it yet, though :p -- [EMAIL PROTECTED] mailing list