bash 脚本:在使用 inotifywait 的简单脚本中读取 while 的含义
#!/bin/sh
inotifywait -qme CREATE --format '%w%f' /tmp/watch | while read f;
do
ln -s "$f" /tmp/other/;
done
我发现这个脚本正在寻找对执行特定工作的文件系统事件做出反应的东西。该脚本工作完美,我不明白的是 while read f; 的含义
#!/bin/sh
inotifywait -qme CREATE --format '%w%f' /tmp/watch | while read f;
do
ln -s "$f" /tmp/other/;
done
I've found this script looking for something that react to filesystem event doing a specific job. The script works perfectly what i don't understand is the meaning of while read f;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它捕获
inotifywait
命令的输出并逐行解析它,将每一行依次分配给while
语句中的f
。该特定的
inotifywait
命令持续监视/tmp/watch
目录,并在创建条目时输出完整路径名。然后,
while
循环处理每个文件名,并在/tmp/other/
目录中创建指向该文件的符号链接。下面是一个示例脚本,显示了
while read
的实际操作:It's capturing the output of your
inotifywait
command and parsing it line by line, assigning each line in turn tof
in thewhile
statement.That particular
inotifywait
command continuously monitors the/tmp/watch
directory and outputs the full path name when an entry is created.The
while
loop then processes each each of those file names and creates a symbolic link to it in the/tmp/other/
directory.Here's an example script showing the
while read
in action: