I have the following so far:
#!/bin/sh
getVersionInfo() {
yarn info my-package version
}
getVersion() {
VERSION_REGEX='^'
$1 =~ $VERSION_REGEX
}
VERSION_INFO=$(getVersionInfo)
VERSION=$(getVersion "$VERSION_INFO")
echo $VERSION
I eventually want to run the script and be able to upgrade all my projects in one command to the latest version of my-package
.
I am stuck on two things:
- why does the console print out TWICE?
- how do i work out the regex (or use another technique) to get the version number?
The yarn info my-package version
output is:
└─ my-package@workspace:shared
├─ Version: 0.0.28
│
└─ Dependencies
├─ @grpc/grpc-js@npm:^1.5.3 → npm:1.5.9
├─ @types/dinero.js@npm:^1.9.0 → npm:1.9.0
├─ @types/gulp-sourcemaps@npm:^0.0.35 → npm:0.0.35
I am using yarn version 3.2.0
CodePudding user response:
Thanks to @kj-crypto the solution requires no functions and can be a one-liner:
VERSION="$(yarn info my-package version | grep -oE 'Version: (?[0-9.]*)' | grep -oE '(?[0-9.]*)')