2

I want to use a globbing pattern to match only printable (including space) ASCII characters 0x20 through to 0x7e. This is being used inside a super super.tab database.

I've arrived at the pattern:

[[ -~]]

This appears to work and does indeed restrict non-printing characters from being passed as arguments.

Have I over looked anything, or is this the correct way to specify this range of characters?

Edit:

Based on mikeserv's suggestion to use [[:print:]], I tried and it doesn't seem to work.

Here's what the entry in my super.tab looks like:

dosuperthing  /system/dosuperthing.pl $Users  uid=0 arg1="[[:print:]]"

If I try [[:print:]], [:print:] or :print: as globbing patterns for arg1 it results in (respectively) the following being logged by super where I pass abcdef as my first argument:

super: (admin) Your argument #1 <abcdef> must match pattern <[[:print:]]>

super: (admin) Your argument #1 <abcdef> must match pattern <[:print:]>

super: (admin) Your argument #1 <abcdef> must match pattern <:print:>

This is old legacy production code and I'm not able to tinker with it beyond tuning the acceptable arg1-99 patterns inside super.tab.

Kev
  • 1,429
  • 7
  • 21
  • 32

1 Answers1

2

The glob pattern or regular expression [ -~] matches all printable characters in the C locale: this matches all characters from 32 (space) to 126 (tilde). In a locale other than C (more precisely, if LC_COLLATE is not C), if the application is locale-aware, this may match other characters.

Another way to write this pattern is [[:print:]]. However, this matches all printable characters in the current locale (based on the LC_CTYPE setting), so it's no better than [ -~] for your use case. Also, it may not work if your application or system library is too antiquated to understand the [:class:] syntax.

Super's [[cHARS]] syntax (if the global option patterns=shell is set) follows the same principle, so it's [[ -~]] to mean “printable ASCII characters only”. Super doesn't set any locale other than LC_CTYPE, so you're safe from that front. Make sure that patterns=shell is set; the default is patterns=regex, which requires that you write ^[ -~]*$ instead.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175