加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 如何解析shell脚本中的命令输出

发布时间:2020-12-14 00:06:24 所属栏目:Linux 来源:网络整理
导读:任何人都可以建议我如何解析下面的命令输出并将特定值存储在变量中. sestatus 这是该命令的输出 SELinux status: enabled SELinuxfs mount: /selinux Current mode: enforcing Mode from config file: enforcing Policy version: 24 Policy from config file
任何人都可以建议我如何解析下面的命令输出并将特定值存储在变量中.

sestatus

这是该命令的输出

SELinux status:                 enabled  
SELinuxfs mount:                /selinux  
Current mode:                   enforcing  
Mode from config file:          enforcing  
Policy version:                 24  
Policy from config file:        targeted

在这里,我想存储当前模式的“强制执行”:在变量中.

任何人都可以建议我.

提前致谢.

解决方法

你可以使用cut或sed,任何实现都可以使用,

[root@giam20 ~]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          enforcing
Policy version:                 24
Policy from config file:        targeted
[root@giam20 ~]# variable=`sestatus | grep 'Current mode'|cut -f2 -d ":"`
[root@giam20 ~]# echo $variable
enforcing
[root@giam20 ~]#

这比上面写的简单.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读