netcat的换行问题 [英] new line issue with netcat
问题描述
我正在使用以下命令将一些字符串发送到udp监听服务器.
I am using below command to send some strings to udp listening server.
回显"A 192.168.192.168" |nc -u 192.168.2.1 1234
echo "A 192.168.192.168" | nc -u 192.168.2.1 1234
但是服务器在回显的字符串中尾随'\ n'.
but the server is getting trailing '\n' in echoed string.
我也尝试过下面的命令,但是失败了
I have tried below command too, but failed
回显"A 192.168.192.168" |nc -uC 192.168.2.1 1234
echo "A 192.168.192.168" | nc -uC 192.168.2.1 1234
如何删除尾随的换行符?我在nc中有什么特殊选择吗?
How can I remove that trailing new line character ?? Do I have any special option in nc ??
推荐答案
echo
通常提供 -n
标志.这不是标准的.
echo
usually provides -n
flag. This is not standard.
string 要写入标准输出的字符串.如果第一个操作数是-n,或者任何一个操作数包含反斜杠('\')char-演员,结果是实现定义的.
string A string to be written to standard output. If the first operand is -n, or if any of the operands contain a backslash ( '\' ) char‐ acter, the results are implementation-defined.
在符合XSI的系统上,如果第一个操作数为-n,则应将其视为字符串,而不是选项.
On XSI-conformant systems, if the first operand is -n, it shall be treated as a string, not an option.
我建议使用 printf
printf "A 192.168.192.168" | nc -u 192.168.2.1 1234
除非被告知,否则
printf
不会添加新行,这是标准行为.
printf
doesnt append a new line unless it is told to, and it's standard behavior.
这篇关于netcat的换行问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!