我需要帮助将一些sed
输出传输到xargs
.这不起作用,没有任何回显:
fswatch -xr mysitedir | sed -n '/Updated$/p' | xargs -L1 -I {} echo {}
我的最终目标实际上不是,而是每当检测到站点目录中的更改时echo
触发我的构建工具 ( soupault
) 。fswatch
该sed
命令基本上可以与grep
我的情况互换。它只是过滤这个事件流:
$ fswatch -xr site
/home/jplew/Sites/projects/soupault/site IsDir
/home/jplew/Sites/projects/soupault/site PlatformSpecific
/home/jplew/Sites/projects/soupault/site IsDir
/home/jplew/Sites/projects/soupault/site/blog/index.html Updated
/home/jplew/Sites/projects/soupault/site/blog PlatformSpecific
/home/jplew/Sites/projects/soupault/site/blog IsDir
/home/jplew/Sites/projects/soupault/site/blog/index.html Updated
/home/jplew/Sites/projects/soupault/site/blog PlatformSpecific
/home/jplew/Sites/projects/soupault/site IsDir
/home/jplew/Sites/projects/soupault/site PlatformSpecific
/home/jplew/Sites/projects/soupault/site IsDir
/home/jplew/Sites/projects/soupault/site/blog/index.html Updated
归结为:
$ fswatch -xr site | sed -n '/Updated$/p'
/home/jplew/Sites/projects/soupault/site/blog/index.html Updated
/home/jplew/Sites/projects/soupault/site/blog/index.html Updated
/home/jplew/Sites/projects/soupault/site/blog/index.html Updated
为什么不xargs
打印任何东西?
答案1
我在这里找到了答案:https://stackoverflow.com/a/23030127/1011766
因为fswatch
这是一个长时间运行的过程,所以我必须使用 sed 的-u
标志来取消缓冲流。
-u, --unbuffered
load minimal amounts of data from the input files and flush the output buffers more often
这个简单的修复就做到了:
fswatch -xr mysitedir | sed -un '/Updated$/p' | xargs -L1 -I {} echo {}
笔记
@cas 针对我的特定用例提供的更好的解决方案是使用 的fswatch
内置 --event 标志:
fswatch --event Updated -0r mysitedir | xargs -0r -I{} echo {}