英文:
How to concatenate netcat data to form a string variable in Bash for email sending?
问题
现在 = ''
nc -lvp 12345 | $now=$now$1
./ForwardMail.sh $now
英文:
Concatenate a string in a pipe, while getting data over netcat
I want to collect data over netcat from a specific port. This data should be transferred to another script and should be send via email. I started a pipe with xargs, but got the problem that every single line is send on its own. Now I wanted to concenate a string over the time of the connection and hand this over to the email sending script, but somehow I can't get the string concatenated
now = ''
nc -lvp 12345 | $now=$now$1
./ForwardMail.sh $now
Could someone help me to concatenate the string?
答案1
得分: 1
对于一个Bash脚本来说,这完全是无意义的。
第一行
now = ''
调用一个名为now
的程序,带有两个参数:=
和一个空字符串。
你正在将nc
的输出传输到一个(格式不正确的)赋值操作中。这毫无意义。顺便说一下:在=
的左侧使用$now
也不是一个好主意。
大多数这些错误都会被shellcheck标记出来。
根据你的描述,我得到的印象是你想要做的是:
netcat=$(nc -lvp 12345)
./ForwardMail.sh "$netcat $1"
但即使这样也似乎很奇怪。可能,下面的方式会更好一些:
netcat=$(nc -lvp 12345|ts)
当然,我们不知道ForwardMail.sh
是什么样的,以及它如何处理不同的行作为参数。
英文:
For a bash script, this is completely nonsense.
The first line
now = ''
calls a program now
with two arguments: =
and an empty string.
You are piping the output of nc
to a (badly formed) assignment. That makes no sense. By the way: using $now
on the left side of the =
is also a bad idea.
Most of these errors wil be flagged by shellcheck
From your description, I get the impression that you want to do:
netcat=$(nc -lvp 12345)
./ForwardMail.sh "$netcat $1"
But even that seems strange. Possibly,
netcat=$(nc -lvp 12345|ts)
would be a better idea.
Ofcourse, we've no idea what ForwardMail.sh
looks like, and what it does with different lines as argument.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论