来自后台线程

时间:2017-04-12 14:41:17

标签: bash

为什么'more'命令在主线程和后台线程上产生不同的输出? 请参阅以下示例:

#!/bin/sh

test_main()
{
   more input.txt > output_main.txt
}

test_back()
{
   more input.txt > output_back.txt
}

echo "abc" > input.txt
test_back &
test_main
wait

output_main.txt:

abc

output_back.txt:

::::::::::::::
input.txt
::::::::::::::
abc

1 个答案:

答案 0 :(得分:1)

more的标准输入必须连接到终端以确定页面的行数。在后台运行more时,stdin不是终端,more正在非交互模式下运行。

$ more input.txt </dev/tty
abc
$ more input.txt </dev/null
::::::::::::::
input.txt
::::::::::::::
abc
相关问题