help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Regex and glob patterns in Parameter Expansion


From: Bipul kumar
Subject: Re: Regex and glob patterns in Parameter Expansion
Date: Sun, 19 Mar 2023 20:32:44 +0530

I think the bash shell parameter expansion is for glob patterns only and
used for substitution.












*root@client:~#str="Hello World"root@client:~#new_str=${str##*
}root@client:~#echo $new_strWorldroot@client:~#str="Hello
World"root@client:~#new_str=${str%% *}root@client:~#echo
$new_strHelloroot@client:~#str="Hello
World"root@client:~#new_str=${str/World/}root@client:~#echo $new_strHello*

glob is basic pattern matching you will find inside the gnu pattern
matching.
And yes Glob patterns are simpler and more limited in scope than regular
expressions.

source:
https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html

    Respectfully,
    Bipul
    PUBLIC KEY <http://ix.io/1nWf>
    97F0 2E08 7DE7 D538 BDFA  B708 86D8 BE27 8196 D466
                    ** Please excuse brevity and typos. **


On Sun, Mar 19, 2023 at 6:50 PM uzibalqa <uzibalqa@proton.me> wrote:

>
> Does Shell Parameter Expansion accept regex or glob patterns?
>
> ${str/$ptrn/}
>
> ${str##$ptrn}
>
> ${str%%$ptrn}/}
>
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]