[TriLUG] detecting kernel major/minor versions

Joseph Mack NA3T jmack at wm7d.net
Mon Jun 26 21:32:17 EDT 2006


On Mon, 26 Jun 2006, Benjamin Reed 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 realised I was only putting the problem off till later, 
but it did what I wanted for the evening

> 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.

much better

Thanks Joe


-- 
Joseph Mack NA3T EME(B,D), FM05lw North Carolina
jmack (at) wm7d (dot) net - azimuthal equidistant map
generator at http://www.wm7d.net/azproj.shtml 
Homepage http://www.austintek.com/ It's GNU/Linux!



More information about the TriLUG mailing list