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

${parameter#word}

“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:

PA=ja-JP/subdir/
echo ${PA##ja*}

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

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

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: