【发布时间】:2016-03-10 21:34:58
【问题描述】:
我想编写一个循环遍历 shell 命令ps 的输出(可能是数组?)的脚本。
这是命令和输出:
$ ps -ewo pid,cmd,etime | grep python | grep -v grep | grep -v sh
3089 python /var/www/atm_securit 37:02
17116 python /var/www/atm_securit 00:01
17119 python /var/www/atm_securit 00:01
17122 python /var/www/atm_securit 00:01
17125 python /var/www/atm_securit 00:00
将其转换为 bash 脚本(sn-p):
for tbl in $(ps -ewo pid,cmd,etime | grep python | grep -v grep | grep -v sh)
do
echo $tbl
done
但是输出变成:
3089
python
/var/www/atm_securit
38:06
17438
python
/var/www/atm_securit
00:02
17448
python
/var/www/atm_securit
00:01
如何像在 shell 输出中一样循环遍历每一行,但在 bash 脚本中?
【问题讨论】: