fswatch 写入然后删除

fswatch write then delete

我正在使用 fswatchwatched.txt 被修改时刷新 refreshed.txt。目前,something 附加到 refreshed.txt

 fswatch -o watched.txt | xargs -n1 sh -c "echo 'something' >> refreshed.txt"

不过我想写something然后删掉

我试过:

fswatch -o watched.txt | xargs -n1 sh -c "echo 'something\b\b' >> refreshed.txt"

fswatch -o watched.txt | xargs -n1 sh -c "echo 'something' >> refreshed.txt && sed -ie '$d' refreshed.txt"

但似乎都没有达到预期的效果。

sed 不是 运行,因为当您将 " 引用的脚本提供给 sh 时,$d 被替换为空字符串:

sed -ie '' refreshed.txt.

您应该转义 $,以避免:

sed -ie '$d' refreshed.txt 

注意添加一行然后立即删除它, 几乎等同于简单地更新它的修改时间戳,所以你可能想让它休眠一会儿,以便变化检测系统赶上。