I am trying to create a bash script with 2 parameters:
- a directory
- a command.
I want to watch the directory parameter for changes: when something has been changed the script should execute the command.
I'm running MacOS, not Linux; any pointers or external resources would greatly help as I have see that this is difficult to achieve. Really OI am trying to mimic SASS's watch functionality.
#!/bin/bash
#./watch.sh $PATH $COMMAND
DIR=$1
ls -l $DIR > $DIR/.begin
#this does not work
DIFFERENCE=$(diff .begin .end)
if [ $DIFFERENCE = '
']; then
#files are same
else
$2
fi
ls -l $DIR > $DIR/.end
See Question&Answers more detail:os