以下测试脚本存在问题。当我在脚本中添加(sleep 5)&
行时,while read
循环不读取文件中的所有行,但只打印第一行。while while循环+在while循环中创建aproccess
但是,当我从脚本中删除(sleep 5)&
时,脚本将打印文件中定义的所有行。
为什么(sleep 5)&
会导致这种情况?
如何解决这个问题?我想在while循环中创建一个新的进程(睡眠只是一个例子)。
$ more test
#!/bin/ksh
while read -r line ; do
echo $line
(sleep 5)&
RESULT=$!
sleep 1
kill $RESULT
done < file
$ more file
123 aaa
234 bbb
556 ccc
KSH哪个版本您使用的?就像吉尔斯提到的,我没有在ksh93t +上看到它 – tomkaith13 2011-06-24 20:41:41