Bash script: reading meaning in a simple script that uses inotifywait


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

I found that this script is looking for something that responds to a file system event that does a specific job. the script works fine, which I don’t understand is the while value when reading f;

+3
source share
1 answer

It writes the output of your command inotifywaitand analyzes it line by line, assigning each line fin the instruction while.

This special command inotifywaitcontinuously monitors the directory /tmp/watchand displays the fully qualified path name at creation.

The loop while, in turn, processes each of these file names and creates a symbolic link in the directory in it /tmp/other/.

script, while read:

pax$ ( echo 1 ; echo 2 ; echo 3 4 ) | while read f
pax> do
pax> echo "[$f]"
pax> done
[1]
[2]
[3 4]
+4

All Articles