3


#!/bin/sh
inotifywait -qme CREATE --format '%w%f' /tmp/watch | while read f; 
do 
ln -s "$f" /tmp/other/; 
done

我发现这个脚本正在寻找对执行特定工作的文件系统事件做出反应的东西。该脚本完美运行我不明白的是while read f的含义;

4

1 回答 1

5

它捕获inotifywait命令的输出并逐行解析,fwhile语句中依次分配每一行。

该特定inotifywait命令持续监视/tmp/watch目录并在创建条目时输出完整路径名。

然后while循环处理每个文件名并在/tmp/other/目录中创建指向它的符号链接。

这是一个显示实际操作的示例脚本while read

pax> printf "1\n2\n3 4\n" | while read f ; do echo "[$f]" ; done
[1]
[2]
[3 4]
于 2011-03-19T15:03:08.133 回答