Basic While loop won't exit...

Hi everyone - just like to say great forum...I've learned a lot off here but I just can't figure this one out...(first post)

I'm writing a script to monitor a directory and email the latest modified file....(I realize there are better ways than I'm trying here...I don't like copying and pasting bits of code...I like to understand what I actually type)

I've figured out how to email the file as an attachment with mutt....so I didn't include that part here...

Can't figure out why the loop won't exit once 'find' gets the file....just keeps repeating the file name...thanks in advance:

temp=""

while [ "$temp = null" ]
do

sleep 1
temp=`find /home/user/My\ Documents/motion_capture/ -amin -2`
echo $temp

done

It might be because "$temp = null" would never evaluate to an empty string, whereas "$temp" = null might evaluate to false.

More likely is that your logic with the while-loop is wrong. Are you hoping to find a single file called "null"?

Or this:

while [ -z "$temp" ]; do
 ....
done

use this

temp="";

while [ "$temp" == "" ]

Hey Scottn - I was playing with the -z option for test...just couldn't get it to work properly...thanks that works perfect! . ...
I'll keep working on my final project now that you got me past that...
what I am working on is a little motion detection system...I have the program 'motion' taking snapshots and saving them on the disk, I need the first one that is created to be emailed to me, since I am just using my webcam (built-in to laptop) - someone could just steal my laptop - so I need the first one to be emailed to myself....I know it sounds simple...but I'm working in a Camp in Northern Alberta Canada, and the cleaning staff here have been stealing etc....thanks again Scottn

== is non-standard and doesn't work in most shells; use =.

Oh i didnot know that this usage is not standard. Thanks for letting me know.