dingyichen (dingyichen) wrote,
dingyichen
dingyichen

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.
Tags: bash. parameter expansion
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

  • 1 comment