当我在下面运行这个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
任何,建议??
答案 0 :(得分:4)
在调用时只需引用变量:
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