How to determine the latest version of the main and full versions of the kernel as compact as possible

So, I'm going to do here to determine both the latest and the full version of the kernel version as compact as possible (without using zillion for grep).

I am already quite pleased with the result, but if anyone has ideas on how to crush the first line, even the slightest, it would be very surprising (it should work when there are no small patches ).

The .org kernel index is only 36 kb compared to 136 kb from http://www.kernel.org/pub/linux/kernel/v3.x/ , so I use it:

_major=$(curl -s http://www.kernel.org/ -o /tmp/kernel && cat /tmp/kernel | grep -A1 mainline | tail -1 | cut -d ">" -f3 | cut -d "<" -f1) pkgver=${_major}.$(cat /tmp/kernel | grep ${_major} | head -1 | cut -d "." -f6) 
+4
source share
2 answers

This is just a thinking exercise at this stage, as the real answer in the comments is above, but here are some possible improvements.

Original:

 _major=$(curl -s http://www.kernel.org/ -o /tmp/kernel && cat /tmp/kernel | grep -A1 mainline | tail -1 | cut -d ">" -f3 | cut -d "<" -f1) 

Use tee instead of cat:

 _major=$(curl -s http://www.kernel.org/ | tee /tmp/kernel | grep -A1 mainline | tail -1 | cut -d ">" -f3 | cut -d "<" -f1) 

Use sed to minimize the number of tubes and make the command unreadable

 _major=$(curl -s http://www.kernel.org/ | tee /tmp/kernel | sed -n '/ainl/,/<\/s/ s|.*>\([0-9\.]*\)</st.*|\1|p') 

Cheap Tricks: Shorten URLs

 _major=$(curl -s kernel.org | tee /tmp/kernel | sed -n '/ainl/,/<\/s/ s|.*>\([0-9\.]*\)</st.*|\1|p') 
+1
source

You have useless use of a cat . You can replace:

 cat /tmp/kernel | grep -A1 mainline 

just:

 grep -A1 mainline /tmp/kernel 

In your case, you do not need a file at all. Curl will produce standard output by default, so you can simply do:

 curl -s http://www.kernel.org/ | grep -A1 mainline 
+1
source

All Articles