I'm trying to make a inotifywait script take different actions for files vs folders if it sees a close_write flag being raised in the watched directory, but cannot seem to get the checks working.In other scripts I use these kinds of checks all the time and they just_work, but there seems to be something about inotifywait I'm not grasping yet.This is the script in its current form:    #!/bin/bash    dir1=/sambashares    while true; do     inotifywait -r -e close_write $dir1 | while read f; do      #debug      echo $f      #Is it a directory?      if [[ -d ${f} ]]; then       #debug       echo New directory called ${f} detected       chown -R jake:jake $f       chmod -R 775 $f       cp -R $f /media/lacie/Film      fi      #Is it a file?      if [[ -f ${f} ]]; then       #debug      echo New file called ${f} detected      chown jake:jake $f      chmod 775 $f      cp $f /media/lacie/Film      fi     done    doneIf I run this in a terminal to see what is happening all I get is the confirmation a close_write was detected, followed by a setting up watches without any other messages or any of the other code being triggered, not even the debug echo directly below: while read f; do:-(I'm running this on Ubuntu server 12.04 LTS 64 bit.$ bash --versionGNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu)$ dpkg -l | grep inotifyii  inotify-tools                    3.13-3ii  libinotifytools0                 3.13-3ii  python-pyinotify                 0.9.2-1$ python --versionPython 2.7.3
inotifywait different action on file or dir
bash;ubuntu;files;directory;inotify
The following works for me:ExampleBelow shows an example of inotifywait using a method similar to your own.$ inotifywait -r -e close_write somedir | while read f; do echo $f hi;doneSetting up watches.  Beware: since -r was given, this may take a while!Watches established.    I then go into the directory somedir and touch afile, touch afile. Which results in this occurring in the inotifywait window:somedir/ CLOSE_WRITE,CLOSE afile hiNOTE: To get all the output from inotifywait you could modify your example slightly:$ inotifywait -r -e close_write somedir 2>&1 | \    while read f; do echo $f | hi;doneSetting up watches.  Beware: since -r was given, this may take a while! | hiWatches established. | hiAnd again touch a file with the command, touch afile, I now see the event:somedir/ CLOSE_WRITE,CLOSE afile | hiFor another example that shows how to use inotifywait take a look at the example I showed in my answer to this Q&A titled: Automatically detect when a file has reached a size limit.Your issueI believe part of your issue is that you're assuming that the output returned from inotifywait is just the file's name while clearly it isn't from the above examples.So these if statements will never succeed:  if [[ -d ${f} ]]; thenand  if [[ -f ${f} ]]; then When developing Bash scripts such as this it's often helpful to enable debugging messages via this command at the top:set -xYou can disable it with this:set +xYou can wrap sections of your code using these messages to turn it on/off.set -x...code...set +x