0

I have this string:

package: name='my.package.name versionCode='221013140' versionName='00.00.05' platformBuildVersionName='12' platformBuildVersionCode='32' compileSdkVersion='32' compileSdkVersionCodename='12'

Using bash, how can I get this value?

00.00.05

2 Answers 2

1

Use parameter expansion:

#!/bin/bash
string="package: name='my.package.name versionCode='221013140' versionName='00.00.05' platformBuildVersionName='12' platformBuildVersionCode='32' compileSdkVersion='32' compileSdkVersionCodename='12'"

version=${string#* versionName=\'}  # Remove everything up to the version name.
version=${version%%\'*}             # Remove everything after the first quote.

echo "$version"
Sign up to request clarification or add additional context in comments.

Comments

1

You can use bash regex matching operator (=~):

[[ $string =~ versionName=\'([^\']*)\' ]] && echo "${BASH_REMATCH[1]}"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.