我会在 shell 脚本中 grep 某些 shell 命令输出的某些部分:
$ uname -r
>> 3.14.37-1-lts
Run Code Online (Sandbox Code Playgroud)
我只需要3.14.37
.
而且对于VERSION
具有值“-jwl35”的shell脚本变量,我只想取值“jwl35”。
如何在 shell 脚本中使用正则表达式?
提前致谢!
~/kernelbuild/linux-3.14.37
我想在我自己的 shell 脚本中使用该目录下另一个 Makefile 中的变量。
以下是我需要的变量:
VERSION = 3
PATCHLEVEL = 14
SUBLEVEL = 37
Run Code Online (Sandbox Code Playgroud)
问题是我不允许更改 Makefile,因此导出变量不是这里的选项。
另外,我看到有人说要有一个单独的文件,其中包含所需的所有常见变量。这很实用,但我需要将所有内容都放在我的单个 shell 脚本中。
我试图包含. ~/kernelbuild/linux-3.14.37/Makefile
在我的 shell 脚本中,我认为我应该能够使用这些变量,但它给了我以下错误:
/home/jl4347/kernelbuild/linux-3.14.37/Makefile: line 1: VERSION: command not found
/home/jl4347/kernelbuild/linux-3.14.37/Makefile: line 2: PATCHLEVEL: command not found
/home/jl4347/kernelbuild/linux-3.14.37/Makefile: line 3: SUBLEVEL: command not found
/home/jl4347/kernelbuild/linux-3.14.37/Makefile: line 4: EXTRAVERSION: command not found
/home/jl4347/kernelbuild/linux-3.14.37/Makefile: line 5: NAME: command not found
/home/jl4347/kernelbuild/linux-3.14.37/Makefile: line 17: MAKEFLAGS: command not found
/home/jl4347/kernelbuild/linux-3.14.37/Makefile: line 20: unexport: command not found
/home/jl4347/kernelbuild/linux-3.14.37/Makefile: …
Run Code Online (Sandbox Code Playgroud)