在shell脚本中使用ncat管道时返回的行重叠

时间:2015-09-17 01:48:53

标签: shell unix sh

我正在使用/ bin / sh编写一个shell脚本,通过ncat从telnet调用中获取数据,如下所示:

echo 'transport info' | ncat hostname 9993

当我从命令行执行此操作时,输出如下所示:

500 connection info:
protocol version: 1.3
model: HyperDeck Studio

208 transport info:
status: record
speed: 0
slot id: 1
clip id: none
display timecode: 00:28:01:27
timecode: 00:00:00:00
video format: 1080i5994
loop: false

但是当我在shell脚本/bin/sh中执行它时,它看起来像这样:

loop: falseat: 1080i599443:15

这是我的示例脚本:

#!/bin/sh
FOO="$( echo "transport info" | ncat -C hostname 9993 )"
echo $FOO

任何人都知道为什么会这样吗?

1 个答案:

答案 0 :(得分:1)

#!/bin/sh
echo "transport info" | ncat -C hostname 9993 | dos2unix > /tmp/test.txt
cat /tmp/test.txt

输出:

500 connection info:
protocol version: 1.3
model: HyperDeck Studio

208 transport info:
status: preview
speed: 0
slot id: none
clip id: none
display timecode: 01:10:01:01
timecode: 00:00:00:00
video format: 1080i5994
loop: false