2

Somtimes you need to manually download a freebsd package (organized by major version) and want to write a script to get it, is there a way to extract the Freebsd major version using freebsd-version and sed?

2
  • Why don't you use pkg fetch? For example pkg fetch -Uy -o ~/ firefox will download the firefox package to your home directory.
    – uzsolt
    May 15 at 11:52
  • @uzsolt : This was on a freenas (aka truenas) system where freebsd ports repo by default is disabled (and I don't feel like enabling it). Not something one would normally do but this was a core-level non-jail package that was needed.
    – Vivek Gani
    2 days ago

2 Answers 2

1

Optionally, cut the string

shell> uname -r
13.0-RELEASE
shell> export FREEBSD_MAJOR_VERSION=`uname -r | cut -d . -f 1`
shell> echo $FREEBSD_MAJOR_VERSION
13
0

considering the format of the version from freebsd-version is something like 12.2-RELEASE-p14 , with sed one could select and replace (s/) the area including and after the first period (\..*) and replace it with null (//) :

FREEBSD_MAJOR_VERSION=`freebsd-version | sed 's/\..*//'`

you can then use it in a script for, say, downloading a package...

wget http://pkg.freebsd.org/freebsd:${FREEBSD_MAJOR_VERSION}:x86:64/[...rest of url...]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.