UNIX:为什么echo不按顺序打印?

时间:2017-08-30 03:08:07

标签: unix echo ksh

我正在此HP-UX环境中编写.ksh脚本,下面显示了它的外观:

IFS=$'\n'       # make newlines the only separator
for j in $(ps -ef | grep ora | grep ORCL | grep "LOCAL=NO" | grep Aug)
do
p=$(echo "$j" | cut -d ' ' -f 3)
echo "$p"
echo "$j"
done

我希望代码打印一个进程ID,然后是一行,然后是一个进程id,然后再一行......依此类推。然而,实际上它首先回应所有过程id,然后是所有行。为什么会这样发生?

2490
2299
2573
2553
2455
2606
2469
2359
2627
4310
2327
2531
2562
2336
2446
3958
2517
2318
2499
2309
2426
2582
2508
2481
2596
2437
2544
2618
2369
2345
oracle 2490     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2299     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2573     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2553     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2455     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2606     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2469     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2359     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2627     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 4310     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2327     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2531     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2562     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2336     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2446     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 3958     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2517     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2318     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2499     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2309     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2426     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2582     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2508     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2481     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2596     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2437     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2544     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2618     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2369     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)
oracle 2345     1  0  Aug  5  ?         0:00 oracleORCL (LOCAL=NO)

0 个答案:

没有答案