shell脚本输出没换行符

Shell脚本输出换行问题
本文介绍了一种在Shell脚本中使用dmesg和grep命令获取USB设备信息的方法,并解决了输出信息中缺失换行符的问题。通过在echo命令中使用双引号,可以正确地展示每条记录。

问题如下:在终端里输入dmesg | grep -i speed命令显示如下

[    1.358314] xhci_hcd 0000:00:14.0: Host supports USB 3.0 SuperSpeed
[    1.690882] usb 1-3: new full-speed USB device number 2 using xhci_hcd
[    1.966868] usb 2-1: new SuperSpeed Gen 1 USB device number 2 using xhci_hcd
[    2.114826] usb 1-6: new high-speed USB device number 3 using xhci_hcd
[    2.426891] usb 1-8: new full-speed USB device number 4 using xhci_hcd
[    2.702893] usb 1-11: new full-speed USB device number 5 using xhci_hcd

在脚本中输出的没有换行符,如下

$ USB_T1=$(dmesg | grep -i speed)
$ echo $USB_T1
[ 1.358314] xhci_hcd 0000:00:14.0: Host supports USB 3.0 SuperSpeed [ 1.690882] usb 1-3: new full-speed USB device number 2 using xhci_hcd [ 1.966868] usb 2-1: new SuperSpeed Gen 1 USB device number 2 using xhci_hcd [ 2.114826] usb 1-6: new high-speed USB device number 3 using xhci_hcd [ 2.426891] usb 1-8: new full-speed USB device number 4 using xhci_hcd [ 2.702893] usb 1-11: new full-speed USB device number 5 using xhci_hcd

解决方法:
使用$ echo "$USB_T1",echo时加上双引号就可以解决问题。

评论 5
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

锡城筱凯

你的鼓励是我创造的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值