2012-11-09 89 views
0

我在这里有一个Ubuntu 12.04服务器,我有一个可以在我的系统中使用一些端口的进程。从grep迭代阵列

我要跟踪这些端口的方法是这样的命令:

ps ax | grep thin | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}\:[0-9]{1,5}'

现在我想用这个命令shell脚本中的数组变量。

如何解析数组中的值?

值如下:

0.0.0.0:3000 0.0.0.0:3001 0.0.0.0:3002 0.0.0.0:3003

谢谢!

+1

见http://stackoverflow.com/questions/918886/split-string-based-on-delimiter-in-bash – sonofagun

回答

2

把你的命令的输出到一个数组:

array=($(ps ax | grep thin | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}\:[0-9]{1,5}')) 
+0

哇。那很简单!非常感谢! = d – Apollo