display-Golang-version-on-bash-prompt

1
2
3
4
5
version=$(go version)
regex="([0-9]{1,2}.[0-9]{1,2}.[0-9]{1,2})"
if [[ $version =~ $regex ]]; then
echo ${BASH_REMATCH[1]}
fi
1
2
3
4
5
6
7
8
9
10
function funcGoVersion {
version=$(go version)
regex="([0-9]{1,2}.[0-9]{1,2}.[0-9]{1,2})"
if [[ $version =~ $regex ]]; then
echo ${BASH_REMATCH[1]}
fi
}

goVersion=$(funcGoVersion)
echo $goVersion

Reference