| From | Alexander Kapshuk <> | Subject | [PATCH 31/32] ver_linux: 'version()' function definition | Date | Tue, 28 Jun 2016 13:19:05 +0300 |
| |
Definition of the 'version()' function. The function encapsulates the algorithm that extracts the version number of the utility being queried, and returns it as a value.
Signed-off-by: Alexander Kapshuk <alexander.kapshuk@gmail.com> --- scripts/ver_linux | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/scripts/ver_linux b/scripts/ver_linux index 3bf72ad..27b43ae 100755 --- a/scripts/ver_linux +++ b/scripts/ver_linux @@ -69,3 +69,14 @@ BEGIN { printversion("Modules Loaded", mods) } } + +function version(cmd, ver) { + while (cmd | getline > 0) { + if (!/ver_linux/ && match($0, /[0-9]+([.]?[0-9]+)+/)) { + ver = substr($0, RSTART, RLENGTH) + break + } + } + close(cmd) + return ver +} -- 2.7.3
|