gpt4 book ai didi

linux - 为什么 wdiff 不适用于命名管道

转载 作者:IT王子 更新时间:2023-10-29 01:03:04 25 4
gpt4 key购买 nike

为什么我可以在 bash 中执行此操作:

$ diff -u <(echo -e "line1\nline2") <(echo -e "line1\nline3")
--- /dev/fd/63 2009-03-30 09:49:07.527272646 +0100
+++ /dev/fd/62 2009-03-30 09:49:07.527272646 +0100
@@ -1,2 +1,2 @@
line1
-line2
+line3

即我可以使用命名管道/进程替换来获取一小段文本的差异。但是,当我尝试使用 wdiff(单词的差异,而不仅仅是行)来执行此操作时,我没有得到任何有用的输出

wdiff <(echo -e "line1\nline2") <(echo -e "line1\nline3")
[--]{++}

更新:看起来有一个现有的 ubuntu 错误报告:https://bugs.launchpad.net/ubuntu/+source/wdiff/+bug/160912

最佳答案

strace 揭示了 wdiff stat 文件(可能是为了找出它们的大小)。由于命名管道报告的大小为 0,因此它可能假设两个文件都是空的,因此是相等的:

$ strace -efile wdiff -1 <(echo -e "line1\nline2") <(echo -e "line1\nline3")execve("/usr/bin/wdiff", ["wdiff", "-1", "/dev/fd/63", "/dev/fd/62"], [/* 44 vars */]) = 0[snip uninteresting stuff]stat64("/dev/fd/63", {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0open("/dev/fd/63", O_RDONLY)            = 3open("/tmp/wdiff.MzPXmH", O_RDWR|O_CREAT|O_EXCL, 0600) = 4stat64("/dev/fd/62", {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0open("/dev/fd/62", O_RDONLY)            = 4open("/tmp/wdiff.5nma9j", O_RDWR|O_CREAT|O_EXCL, 0600) = 5--- SIGCHLD (Child exited) @ 0 (0) ---unlink("/tmp/wdiff.MzPXmH")             = 0unlink("/tmp/wdiff.5nma9j")             = 0{++}Process 27699 detached

编辑:另请注意,如果内核支持,bash 可能会使用 /dev/fd 样式的文件名而不是命名管道(最近的支持,上面的示例显示了这一点),但效果几乎相同。

关于linux - 为什么 wdiff 不适用于命名管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/696463/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com