bash script: meaning of while read in a simple script that use inotifywait
#!/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;
It's capturing the output of your inotifywait command and parsing it line by line, assigning each line in turn to f in the while 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:
pax> printf "1\n2\n3 4\n" | while read f ; do echo "[$f]" ; done
[1]
[2]
[3 4]
加载中,请稍侯......
精彩评论