I want make a script that runs in background (with &) and checks if a certain file, the name of which is read from the keyboard, exists in multiple directories, given as parameter.
So the script will run in a while true loop, until the file with the given name is created.
The problem is, when I run the script, what I type from read is taken as a normal terminal cmd.
Here's the script:
#!/bin/bash
echo Type the file name
read fileName
while true
do
for file in $@
do
if find $file -name $fileName | grep -q "$fileName"
then
echo The file with name $fileName has been created!!!
break
fi
done
done
If I don't run the script with &, it works fine.
scriptname.sh filename-> in your script the filename will be accesible via$1variable ($1 is the first parameter $2 second ... ). how-to.wikia.com/wiki/…inotifywaitinstead of hammering your disk (or cache) with a while loop.