Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
';lsb#U发布-a';在bash脚本中使用另一行时打印该行_Bash_Shell_Lsb - Fatal编程技术网

';lsb#U发布-a';在bash脚本中使用另一行时打印该行

';lsb#U发布-a';在bash脚本中使用另一行时打印该行,bash,shell,lsb,Bash,Shell,Lsb,我正在编写一个bash脚本,其中有一个子任务,用于打印运行系统的Ubuntu名称。 我做到了: Ubuntu12.04 LTS存储在变量Ubuntu\u ver中,但在顶部打印了额外的行。结果是: No LSB modules are available. Ubuntu 12.04.4 LTS 如何防止打印“无LSB模块…” 事实上,每当我试图从命令'lsb_release-a'将某些内容存储在变量中时,就会打印这一行 事实上,每当我试图将某个东西存储在一个文件中时,就会打印出这一行 来自命令

我正在编写一个bash脚本,其中有一个子任务,用于打印运行系统的Ubuntu名称。 我做到了:

Ubuntu12.04 LTS存储在变量Ubuntu\u ver中,但在顶部打印了额外的行。结果是:

No LSB modules are available.
Ubuntu 12.04.4 LTS
如何防止打印“无LSB模块…”
事实上,每当我试图从命令'lsb_release-a'将某些内容存储在变量中时,就会打印这一行

事实上,每当我试图将某个东西存储在一个文件中时,就会打印出这一行 来自命令lsb_release-a的变量

这表明有问题的行实际上是一条错误消息。丢弃它:

ubuntu_ver=$(lsb_release -a 2>/dev/null | grep Description | cut -d":" -f2)

-a
包括返回lsb模块列表的
-v
,这就是为什么您会收到未找到模块的消息

另外,我建议只要求提供描述(
-d
),并省略标题(
-s
):

ubuntu_ver=$(lsb_release -a 2>/dev/null | grep Description | cut -d":" -f2)
ubuntu_ver=$(lsb_release -ds)
echo $ubuntu_ver