Definite's Extractor

My findings on Life, Linux, Open Source, and so on.

Matching prefix pattern in Bash Parameter Expansion

According to bash manpage, when doing parameter expansion like


“The word is expanded to produce a pattern just as in pathname expansion.”

Indeed, the pathname expansion is glob expansion, however, unlike normal pathname expansion, the ‘*’ actually matches ‘/’. In other words:

echo ${PA##ja*}

outputs "",
instead of "/subdir/",
because ja* matches ja-JP/subdir/.

So please treat * as if it is ‘.*’ in regex.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: