The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how can i put the condition in for loop for the below. mail2sant Shell Programming and Scripting 1 04-28-2008 04:49 AM
Checking condition inside the loop ithirak17 Shell Programming and Scripting 1 03-13-2008 08:37 AM
What condition to be put in the while loop? nehaquick UNIX for Dummies Questions & Answers 1 02-15-2008 04:06 PM
End of loop condition required??? skyineyes Shell Programming and Scripting 4 07-16-2007 03:10 AM
how to get the similar function in while loop or for loop trynew Shell Programming and Scripting 3 06-17-2002 11:09 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-01-2008
mavsman mavsman is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 17
Testing For Loop condition

How do I test the return condition in the script if no files are found:

for file in `Find ${LANDING_FILE_DIR}${BTIME_FILENAME_PATTERN}`

do
...
..
done

I want to capture the return code so I can echo the error or condition. Using if [[ $# -eq 0 ]] always returns zero no matter where it's placed.


tia
  #2 (permalink)  
Old 04-01-2008
pupp's Avatar
pupp pupp is offline Forum Staff  
cap_10hdx 1
  
 

Join Date: Feb 2008
Location: Jersey Shore
Posts: 548
are you looking for something like:

if [ -e $filename] then
...


this will check if the file exists.
  #3 (permalink)  
Old 04-01-2008
mavsman mavsman is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 17
I do the following a check for -s and -r. The find statment in the for loop issues a bad status:

find: bad status-- /home/rnitcher/test/BTIME_ACTUAL_WORK_HRS_wk_[0-9][0-9]_to_[0-9][0-9].csv

I need to capture this return from the find command and exit the program cleanly.

tia
  #4 (permalink)  
Old 04-01-2008
pupp's Avatar
pupp pupp is offline Forum Staff  
cap_10hdx 1
  
 

Join Date: Feb 2008
Location: Jersey Shore
Posts: 548
maybe i'm not fully understanding what you're trying to do here... always possible!

you want to see what the return code is of a condition?
  #5 (permalink)  
Old 04-01-2008
mavsman mavsman is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 17
yes I think so.


...
for file in `find ${LANDING_FILE_DIR}${bTIME_FILENAME_PATTERN1}`

do
....

running the script I get the following find error:

find: bad status-- /.../BTIME_ACTUAL_WORK_HRS_wk_[0-9][0-9]_to_[0-9][0-9].csv

so I'm looking for a way in the script to capture the fact that no file(s) where found and not just have the script abort with the the find: bad status message....

tia
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0