我试图了解“>>”作品。它是使用自动附加模式还是lseek?
我已经下载了bash源代码并且一直在试图找到它是如何工作的,但我一直没有成功。也许有更好的方法?
答案 0 :(得分:3)
最简单的方法是通过系统调用来运行bash with strace。你可以这样做:
$ strace -o bash.log bash
$ echo hello >> test.txt
$ echo goodbye >> test.txt
$ exit
$ grep test.txt bash.log
open("test.txt", O_WRONLY|O_CREAT|O_APPEND, 0666) = 3
open("test.txt", O_WRONLY|O_CREAT|O_APPEND, 0666) = 3
write(3, "echo hello >> test.txt\necho good"..., 48) = 48
您可以通过传递给open()
来电的标记看到,它是直接以附加模式打开的。