我有一个关于 bash 的问题,命令如下:
echo helloworld > hello.txt
cat <hello.txt >hello.txt
首先,hello.txt中有一些东西。我期望的是,执行命令后 hello.txt 看起来应该没有任何反应,但 hello.txt 中什么也没有。
这是 bash 的一种机制,还是我对 linux 文件描述符有什么不明白的地方?
也许bash只为某个文件建立一个fd?我说得对吗?
你能帮助我吗?
/br
阮
最佳答案
使用临时文件
cat hello.txt > /var/tmp/tmpFile
mv -f /var/tmp/tmpFile hello.txt
cat hello.txt
关于linux bash 重定向与 stdin 和 stdout 相同的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22063718/