如何在Emacs中获得linux版本

时间:2017-10-08 08:51:54

标签: linux emacs version

我正在寻找一种如何在Emacs Lisp中获取Linux版本的方法,无论表单是字符串还是数字。 如果有,请留下您的代码段。

感谢。

1 个答案:

答案 0 :(得分:1)

您可以将uname -r作为shell命令调用。

(defun my-linux-version ()
  "Return the linux version as a string."
  (shell-command-to-string "printf %s $(uname -r)"))
ELISP> (my-linux-version)
"4.4.0-96-generic"

编辑:

  

修剪部分-generic

(defun my-linux-version ()
  "Return the linux version as a string."
  (let ((version (shell-command-to-string "printf %s $(uname -r)")))
    (replace-regexp-in-string "-generic$" "" version)))