[TriLUG] detecting kernel major/minor versions

Rick DeNatale rick.denatale at gmail.com
Thu Jun 29 13:07:56 EDT 2006


On 6/26/06, Benjamin Reed <rangerrick at befunk.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Joseph Mack NA3T wrote:
>
> > uname_r=`uname -r`
> > minor_and_subminor=${uname_r##*2.6.}
> > minor=${minor_and_subminor%\.*}
>
> Bash stuff works, although this will fail when 2.7 comes out...  <grin>
>
> I generally use "cut" for such things, it tends to be more future-proof:
>
> minor_and_subminor=`echo $uname_r | cut -d. -f3-`
> minor=`echo $uname_r | cut -d. -f3`
>
> - -d. means chop up the string on the "."s
> - -f3 means display the 3rd entry in the chopped string
> - -f3- means display the 3rd entry and anything afterwards
>
> you could also do "-f3-4" to specifically ask for the 3rd through the 4th.

Teacher! Teacher!

I'm missing something here, in my case both forms of the -f parm give
the same results:

rick at bill:~$ uname -r
2.6.15-25-686
rick at bill:~$ uname -r | cut -d. -f3-
15-25-686
rick at bill:~$ uname -r | cut -d. -f3
15-25-686


Rick DeNatale

IPMS/USA Region 12 Coordinator
http://ipmsr12.denhaven2.com/

Visit the Project Mercury Wiki Site
http://www.mercuryspacecraft.com/



More information about the TriLUG mailing list