Bash, overwrite using file descriptor?
问题 If you want to overwrite a file with Bash, this is easy echo "Hello world" > hosts This does not seem to work with a file descriptor $ exec 3<> hosts $ echo "Hello world" >&3 $ cat hosts Hello world $ echo "Hello world" >&3 $ cat hosts Hello world Hello world 回答1: That's correct. The mode in which a file is opened is determined when the shell calls open(2) . When you DUP2 an FD (in any language), the flags that were set when the file was opened are shared between open FDs. In your case, O