I'm trying to make a script in bash. This script is supposed to either exit with prompt if file does not exist, or if it does exit it will exit with prompt once modified, or deleted. The parameter $1 is for the filename, and the parameter $2 is for time intervals between each check. Will it be sufficient to use the -N to check whether the file is modified? Code so far(few small errors which im working on):
#!/bin/bash
running=true;
while[ $running ]
do
if [ ! -f $1 ]; then
echo "File: $1 does not exist!"
running=false;
fi
if [ -f $1 ]; then
if [ ! -N $1 ]; then
sleep [ $2 ]
fi;
elif [ -N $1 ]; then
echo "File: $1 has been modified!"
running=false;
fi;
fi;
done;
running=1/running=0andwhile (( running )); do.trueandfalsedon't have special meaning to bash unless you run them as commands.[ ]to[[ ]]or be sure to double-quote all your expansions. That is to say, either[[ -f $1 ]]or[ -f "$1" ], but not[ -f $1 ].sleep "$2", notsleep [ $2 ]. Square-brackets are a synonym for the "test" command, and the test command is not part of sleep's syntax. (It's not part ofif's syntax either, but that's a separate issue).break, so you don't need arunningflag at all.