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 Answers
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
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...]
pkg fetch
? For examplepkg fetch -Uy -o ~/ firefox
will download the firefox package to your home directory.