printf "%-30s:%-15s\n" report_selinux_enable $report_selinux_enable
printf "%-30s:%-15s\n" report_selinux_status $report_selinux_status
printf "%-30s:%-15s\n" report_os $report_os
printf "%-30s:%-15s\n" report_hostname $report_hostname
printf "%-30s:%-15s\n" report_kernel $report_kernel
printf "%-30s:%-15s\n" report_uptime $report_uptime
printf "%-30s:%-15s\n" report_date_time $report_date_time
输出:
report_selinux_enable :disabled
report_selinux_status :Disabled
report_os :GNU/Linux
report_hostname :centos.com
report_kernel :3.10.0-693.2.2.el7.x86_64
report_uptime :42
days :
report_date_time :2018-07-18-20-24-23
可以看出输出的在线天数(report_uptime)的值是42(本来是42 days),下面还有一行显示的有问题,把一行拆成了两行显示,是因为report_uptime的值中间有空格,所以被拆成两行
解决:printf语句后面的引用值要放在""中
printf "%-30s:%-15s\n" report_uptime "$report_uptime"
printf "%-30s:%-15s\n" "report_selinux_enable" "$report_selinux_enable"
printf "%-30s:%-15s\n" "report_selinux_status" "$report_selinux_status"
printf "%-30s:%-15s\n" "report_os" "$report_os"
printf "%-30s:%-15s\n" "report_hostname" "$report_hostname"
printf "%-30s:%-15s\n" "report_kernel" "$report_kernel"
printf "%-30s:%-15s\n" "report_uptime" "$report_uptime"
printf "%-30s:%-15s\n" "report_uptime" "$report_date_time"
report_selinux_enable :disabled
report_selinux_status :Disabled
report_os :GNU/Linux
report_hostname :centos.com
report_kernel :3.10.0-693.2.2.el7.x86_64
report_uptime :42 days
report_date_time :2018-07-18-20-27-40
喜欢的点点关注,点点赞。
对Java技术,架构技术感兴趣的同学,欢迎加QQ群585550789,一起学习,相互讨论。
群内已经有小伙伴将知识体系整理好(源码,笔记,PPT,学习视频),欢迎加群领取。
网友评论