How to extract last part of string in bash?

后端 未结 6 1548
谎友^
谎友^ 2020-12-28 12:39

I have this variable:

A="Some variable has value abc.123"

I need to extract this value i.e abc.123. Is this possible i

6条回答
  •  长情又很酷
    2020-12-28 12:51

    Some examples using parameter expansion

    A="Some variable has value abc.123"
    echo "${A##* }"
    
    abc.123
    

    Longest match on " " space

    echo "${A% *}"
    
    Some variable has value
    

    Longest match on . dot

    echo "${A%.*}"
    
    Some variable has value abc
    

    Shortest match on " " space

    echo "${A%% *}"
    
    some
    

    Read more Shell-Parameter-Expansion

提交回复
热议问题