相关疑难解决方法(0)

为什么`command 1>file.txt 2>file.txt` 的行为与`command 1>file.txt 2>&1` 的行为不同?

当您想将 stdout 和 stderr 重定向到同一个文件时,可以使用command 1>file.txt 2>&1, 或command &>file.txt。但是为什么command 1>file.txt 2>file.txt与上面两个命令的行为不同呢?

以下是验证命令。

$ cat redirect.sh
#!/bin/bash

{ echo -e "output\noutput" && echo -e "error" 1>&2; } 1>file.txt 2>&1
{ echo -e "output\noutput" && echo -e "error" 1>&2; } 1>file1.txt 2>file1.txt
{ echo -e "error" 1>&2 && echo -e "output\noutput"; } 1>file2.txt 2>file2.txt
{ echo -e "output" && echo -e "error\nerror" 1>&2; } 1>file3.txt 2>file3.txt
{ echo -e "error\nerror" 1>&2 && echo -e "output"; } …
Run Code Online (Sandbox Code Playgroud)

shell bash io-redirection echo

21
推荐指数
2
解决办法
4144
查看次数

什么是打开的文件描述?

当您 fork 一个进程时,子进程继承其父进程的文件描述符。我知道当发生这种情况时,子进程会收到一份父文件描述符表的副本,每个表中的指针都指向相同的打开文件描述。这是与文件表相同的东西,如http://en.wikipedia.org/wiki/File_descriptor,还是其他东西?

file-descriptors fork processes

8
推荐指数
2
解决办法
7175
查看次数

标签 统计

bash ×1

echo ×1

file-descriptors ×1

fork ×1

io-redirection ×1

processes ×1

shell ×1