Using bash script I need to search string like version = '1.8.1-SNAPSHOT' from text file and get value '1.8.1-SNAPSHOT' into variable.
I tryed to use the next code, but no result:
version=$(grep -P "version\s?=\s?'([a-zA-Z.\d-]){5,20}?'" file.txt)
regex="'([a-zA-Z.\d-]){5,30}?'"
value=`expr match "$version" '([a-zA-Z.\d-]){5,30}?'`
What is wrong and are there another way?
Some of text file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath('org.springframework.boot:spring-boot-gradle-plugin:1.5.2.RELEASE')
}
}
springBootVersion = '2.0.7.RELEASE'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
// for Glassfish
//apply plugin: 'war'
jar {
baseName = 'work-space'
version = '1.8.1-SNAPSHOT'
}
Desired string need to be '1.8.1-SNAPSHOT' into variable for the next manipulation.
version="$(grep -oP "version\s*=\s*'\K[^']+" file)". See ideone.com/LtxK2g1.8.1-SNAPSHOT- isn't it expected?