The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's manas6 UNIX for Dummies Questions & Answers 0 06-05-2008 06:44 AM
display the result of wc -l with words before and after the result melanie_pfefer UNIX for Dummies Questions & Answers 3 04-30-2008 07:33 AM
pick the bug the server enters an infinite loop arjunjag High Level Programming 3 07-19-2007 01:53 AM
New iteration of for-loop without incrementing? jeriryan87 Shell Programming and Scripting 0 07-02-2007 02:13 PM
Regex to pick up name from the following including carriage return at end of the line Shakey21 Shell Programming and Scripting 3 07-18-2002 08:27 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-21-2008
Registered User
 

Join Date: Mar 2008
Posts: 27
Pick up the return code for every iteration and display the result only once in loop.

Hi All,
I amlearning UNIX scripting. I have a small query. I would be thankful if any one helps me out.

I have a below piece of code which delets the files. If file dosent have the permissions to delete a particular file I have used 2>>operator to track the error code.

But my objective is to check the return of 'rm' for every iteration.
Some thing like we should be picking up the return code, if its value is greater than 0 then you should set a flag to indicate that an error has occured.
The flag should be initialised to zero before the iterations begin. And the error message some thing like 'Atleast one file cannot be deleted'.

Example:-we need to remember using a flag (something like if [[ $? > 0 ]] then rm_errorflag=1). Need to use this in below piece of code

ls -l | { while read myline;
do
if [[ -f "$myline" && "$myline" != *.ksh ]]
then
echo "Removing " "$myline" >> temp
rm -f "$myline" 2>>temp
fi
done }

Please help me out in this.
Thanks for your time.

Regards,
Manas
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-21-2008
wempy's Avatar
Registered User
 

Join Date: Jun 2006
Location: Harpenden, UK
Posts: 205
add to this to the end of the rm line:
Code:
rm -f "$myline" 2>>temp || rm_errorflag=1
which will set the rm_errorflag if rm's exit value is greater than 0
Reply With Quote
Google The UNIX and Linux Forums
Reply

Bookmarks

Tags
None

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:




All times are GMT -4. The time now is 06:44 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66