nua7
September 25, 2008, 5:19am
1
Hi All,
I have a script which runs 3 scripts. The first script creates two files. The other two scripts should run only when the files are created.
I tried the following for loop , but it is not working. Can someone please help me.
while [ ! -e script3.lck && script4.lck ]; do
# Sleep until file does exists/is created
sleep 1
done
era
September 25, 2008, 5:25am
2
Your "and" conditional is wrong, you need to repeat the -e
while [ ! -e script3.lck -a ! -e script4.lck ]; do
The && goes between two commands, like this:
while [ ! -e script3.lck ] && [ ! -e script4.lck ]; do
or you could change the flow entirely, to avoid those pesky negations:
while true; do
test -e script3.lck && test -e script4.lck && break
sleep 1
done
nua7
September 25, 2008, 5:29am
3
Thanks a lot era! But in this case, even if one file is created , the while loop ends. Ideally it should end if both the files exist.
Any idea, where I have gone wrong..?
nua7
September 25, 2008, 5:34am
4
whoops sorry for the confusion.. I tried your first suggestion, and it didn't work.
I tried your last suggestion, and works as a charm!!
Thanks a lot era!!!
era
September 25, 2008, 5:41am
5
Sorry, I guess precedence problem, the negation covers the whole of the following expression even across an -a apparently. In other words, the second ! in the first solution is wrong, and should be taken out. Another reason to avoid pesky negations I suppose ...