Bash 和 (graphviz) 点输出重定向

标签 bash graphviz dot

我是一名 Bash 新手,努力在目标文件发生更改时自动运行点命令。我想要输出 .png在文件查看器中打开,并在 .dot 上更新图像文件保存。

我尝试了一个衬垫,但没有效果(我认为存在缓冲问题,因此没有输出?):

inotifywait -m --timefmt '%H:%M' --format '%T %w %e %f' -e close_write . |
awk '{print $4}' | dot $1 -Tpng -o foo.png

转向基本的 Bash 脚本,我尝试过:

#!/bin/sh
MONITORDIR="./foo.dot"
inotifywait -m --timefmt '%H:%M' --format '%T %w %e %f' -e close_write "${MONITORDIR}" | while read TIME DIR EVENT FILE
do
    echo $FILE;
    dot -Tpng ${FILE} -o 'foo.png';
done

但是根据 -o 的使用,会出现各种问题。标志与重定向(最多 2>&1 )*。通常输出文件是空白的。我宁愿避免深入 bashland,但是:我应该采取什么不同的做法?这不应该是一件小事吗?

<子>* 例如,Warning: <stdin>: syntax error in line 1 near '16'

最佳答案

Etan 的评论导致了一个工作版本:

#!/bin/sh
MONITORDIR="./foo.dot"
inotifywait -m --timefmt '%H:%M' --format '%T %w %e %f' -e close_write "${MONITORDIR}" | while read TIME DIR EVENT FILENAME
do
    echo $TIME;
    echo $DIR;
    echo $EVENT;
    echo $FILENAME;
    dot -Tpng $DIR -o 'foo.png';
done

值得注意的是,裸露的 watch 语句有 4 个位置参数,但 bash 看到的变量是不同的:

me@comp:~/Projects/inotifytest$ inotifywait -m --timefmt '%H:%M' --format '%T %w %e %f' -e close_write .
Setting up watches.
Watches established.
17:23 ./ CLOSE_WRITE,CLOSE foo.dot

对比

me@comp:~/Projects/inotifytest$ sh dotwatch.sh
Setting up watches.
Watches established.
17:22
./foo.dot
CLOSE_WRITE,CLOSE
<Intentionally blank>

编辑点文件会导致实时图形更新。谢谢大家!

关于Bash 和 (graphviz) 点输出重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34935204/

相关文章:

bash - awk 子替换中的奇怪行为

graphviz - 在 GraphViz 中制作图例/键

python - 使用自循环标记图中的边权重

python - 在一个点文件中解析多个有向图

bash - 使用 crontab 备份 Git Repo 的 Shell 脚本

linux - 检查文件是否真的可以在 bash 中打开

alignment - 在 GraphViz 中将多个短节点与单个高节点并行排列

graphviz - DOT - 如何减少连接两个节点的线

git - 缩进 Bash 脚本输出

python - 从随机森林中获取树木