Basic While loop won't exit...


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Basic While loop won't exit...
# 1  
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:
Code:
temp=""

while [ "$temp = null" ]
do

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

done


Last edited by Scott; 01-06-2010 at 12:04 AM.. Reason: Please use code tags
# 2  
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:

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


Last edited by Scott; 01-06-2010 at 12:33 AM.. Reason: changed "find" to "while-loop" - typo
# 3  
use this
Code:
temp="";

while [ "$temp" == "" ]

# 4  
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

Last edited by Scott; 01-06-2010 at 12:46 AM.. Reason: You're welcome, but too much info....
# 5  
Quote:
Originally Posted by daptal
use this
Code:
temp="";

while [ "$temp" == "" ]


== is non-standard and doesn't work in most shells; use =.
# 6  
Quote:
Originally Posted by cfajohnson

== 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.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #39
Difficulty: Easy
IC chips for computer systems are usually made of silicone.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Basic FOR loop with break

Oracle Linux : 6.4/bash shell In the below I want to break out of the loop when it enters the 5th iteration. #!/bin/bash for i in 1 2 3 4 5 6 do echo "$i" if echo "Oh Nooo... i = $i. I need to stop the iteration and jump out of the loop" then break fi done But, it only... (3 Replies)
Discussion started by: John K
3 Replies

2. Shell Programming and Scripting

Basic help improving for in loop

I'm obviously very new to this. I'm trying to write a simple for loop that will read the directory names in /Users and then copy a file into the same subdir in each user directory. I have this, and it works but it isn't great. #!/bin/bash HOMEDIRS=/Users/* for dirs in $HOMEDIRS; do if ];... (5 Replies)
Discussion started by: Heath_T
5 Replies

3. Shell Programming and Scripting

Trying to run a basic for loop

OS : RHEL 6.1 Shell : Bash I had a similair post on this a few weeks back. But I didn't explain my requirements clearly then. Hence starting a new thread now. I have lots of files in /tmp/stage directory as show below. I want to loop through each files to run a command on each file. I... (8 Replies)
Discussion started by: kraljic
8 Replies

4. Shell Programming and Scripting

Bash won't exit as expected

Hi there, following code snippet should output nothing, IMHO. But the result is "THE END". #!/bin/bash if true ; thenexit fi | grep "somesearchstring" echo "THE END"using bash 4.1.9(1) Bug or feature? Hagen (5 Replies)
Discussion started by: montour
5 Replies

5. Emergency UNIX and Linux Support

For loop exit

Below for loop not exiting. Can someone help? JBOSS_INST_ARGS=01 02 if ; then for i in $JBOSS_INST_ARGS; do /u/jboss-6.1.0.Final/bin/jboss_init_wise$i.sh start; done (8 Replies)
Discussion started by: vino_hymi
8 Replies

6. Shell Programming and Scripting

Exit from loop

hi, how to exit from "if" loop?actually i have mutliple "if" conditions, i have to exit from each "if" loop,if it is true...:confused: Please suggest me... (3 Replies)
Discussion started by: sreelu
3 Replies

7. Shell Programming and Scripting

Null Handling in Until loop. . .loop won't stop

Hi Im running this script, which is supposed to find the max value build some tables and then stop running once all the tables are built. Thing is , it keeps assigning a null value to $h and then $g is null so it keep building tables i.e. testupdateNUL. How can I stop this? Here is what I have: ... (4 Replies)
Discussion started by: brandono66
4 Replies

8. Shell Programming and Scripting

really basic for loop question

sorry for being dumb here, but is there a way my for loop can take an entire line of a file into consideration instead of each word in a line... ill explain if i have a file like this # cat list serial: 23124 hostname: server1 and a script that does this # cat list.sh #!/bin/sh ... (6 Replies)
Discussion started by: hcclnoodles
6 Replies

9. UNIX for Dummies Questions & Answers

A basic question of FOR loop

Hi, have a basic query. Please see the below code: list="one two three" for var in $list ; do echo $var list="nolist" Done Wht if I want to print only first/ last line in the list Eg one & three Regards er_ashu (3 Replies)
Discussion started by: er_ashu
3 Replies

10. Shell Programming and Scripting

while loop exit

i wrote a while script as part of a huge program. this script, once picked, begins to output data to the person using it. pretty easy, as the person doesn't have to keep typing commands to get the output that the while loop automatically throws out. now, the thing is, while this while-script... (3 Replies)
Discussion started by: Terrible
3 Replies

Featured Tech Videos