当我在结果下方运行此bash脚本时,我的结果都在同一行上回荡,如下面的"示例输出"。
#!/bin/bash
Commander=$(nmap -vv -p 8080 xxx.149.xxx.100-xxx |
grep "Discovered open port 8080/tcp on" | sed -r 's/^.{32}//');
echo $Commander;
示例输出:
xx.149.xx.115 xx.149.xx.107 xx.149.xx.107 xx.149.xx.101 xx.149.xx.118 xx.149.xx.146
我想要的是:
xx.149.xx.115
xx.149.xx.107
xx.149.xx.107
xx.149.xx.101
xx.149.xx.118
xx.149.xx.146
xx.149.xx.19
有建议吗?
调用时只需引用您的变量:
echo "$Commander"
样本
$ myvar="hello
> i am fedor
> fedorqui"
$ echo $myvar
hello i am fedor fedorqui
$ echo "$myvar"
hello
i am fedor
fedorqui
因此,您有空间分离的输出,并且您希望它是新的行分开吗?如果是这样,将管道通往tr ' ' 'n'
,将进行此更换。
$ d="a b c"
$ echo "$d" | tr ' ' 'n'
a
b
c