SubString in Bash

This is a note for myself.

I have a string “version=1.234.5” and I want to get the value after the equal and keep the value in a variable. Here is what I have done.

 test_str="version=2.150.2"
 echo $test_str
 ver=${test_str##*=}
 echo $ver

In addition, if I want to retain the part before the equal…

key=${test_str%=*}

Bash looks so cryptic… I use it for wherever necessary but not my favorite language.

Author: admin

A software engineer in greater Seattle area

Leave a Reply

Your email address will not be published. Required fields are marked *