脏变 - 删除回车 [英] Dirty Variable - Remove Carriage return

查看:93
本文介绍了脏变 - 删除回车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下变量。

 回声| $ COMMAND |

返回

  |
REBOOT |

我怎样才能删除第一个回车?


解决方案

 回声| $ COMMAND || TR的'\\ n'''

将取代换行符(POSIX中/ Unix上它不是一个回车)有一个空格。

说实话,我会考虑从bash的切换虽然客场东西更理智。或避免在首位产生这种畸形数据。

嗯,这个,好像它可能是一个可怕的安全漏洞以及具体情况取决于数据的来源。

I have the following variable.

echo "|$COMMAND|"

which returns

|
REBOOT|

How can i remove that first carriage return ?

解决方案

echo "|$COMMAND|"|tr '\n' ' '

will replace the newline (in POSIX/Unix it's not a carriage return) with a space.

To be honest I would think about switching away from bash to something more sane though. Or avoiding generating this malformed data in the first place.

Hmmm, this seems like it could be a horrible security hole as well, depending on where the data is coming from.

这篇关于脏变 - 删除回车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆