Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash读取和stderr重定向_Bash_Redirect - Fatal编程技术网

Bash读取和stderr重定向

Bash读取和stderr重定向,bash,redirect,Bash,Redirect,所以我有一个脚本,在另一个脚本上运行测试用例。我试图在运行测试用例时重定向stderr。给我带来问题的部分是read命令: 在script1中: read -p "Delete $file? (y/n) " input 在testscript中: $script $opts $file 2>/dev/null 来自script1的读取调用也会被重定向。将提示重定向到stdout read -p "Delete $file? (y/n) " input 2>&1 你可以简

所以我有一个脚本,在另一个脚本上运行测试用例。我试图在运行测试用例时重定向stderr。给我带来问题的部分是read命令:

在script1中:

read -p "Delete $file? (y/n) " input
在testscript中:

$script $opts $file 2>/dev/null

来自script1的读取调用也会被重定向。

将提示重定向到stdout

read -p "Delete $file? (y/n) " input 2>&1
你可以简单地说:

echo "Delete $file? (y/n)"
read input

为什么读取调用首先要发送到stderr?我的bash手册页中就是这样记录的:
-p prompt:Display prompt on standard error[…]
>为什么读取调用首先要发送到stderr。。。我将把打印提示到stderr称为特性。如果您只有两个流要使用,stdout和stderr,那么您希望将实际数据转到stdout,这样只剩下stderr用于传递非数据信息。(也就是说,stderr可以用于错误消息之外的其他信息流)。。。祝你好运