Sponsored Content
Full Discussion: Exit always returns 0
Top Forums Shell Programming and Scripting Exit always returns 0 Post 303021508 by Corona688 on Saturday 11th of August 2018 12:39:59 PM
Old 08-11-2018
find simply doesn't return nonzero unless something prevents it from doing what you asked it to do. If it tries to do open a directory and the system tells it "Permission denied", that's an error for example. "Zero files" on the other hand is not an error, just a fact.

Anyway your use of $RETVAL is wrong, because nothing ever changes it. It remains the same throughout your entire program. Using $? instead would also be wrong, because everything changes it -- every time you run any program or test any condition, that changes the value of $?. Even [ $? -eq 0 ] changes the value of $? afterwards. If you want to do more complicated logic in your shell script, use proper if/then statements, case statements, and the like.

What I might try is something like this:

Code:
# Always quote your variables
find "${Docs_Backups}" -mindepth 1 -mtime +3 -print -delete > "/tmp/$$"

if [ -s "/tmp/$$" ]
then
        echo "Found some files"
else
        echo "Found zero files"
fi

rm -f "/tmp/$$"

/tmp/$$ is a simple way of making a random temporary file, since $$ is your process ID and ought to be unique while your program is running.

-s is true when the file has any contents, false when it has no contents.

Last edited by Corona688; 08-11-2018 at 01:48 PM..
These 2 Users Gave Thanks to Corona688 For This Post:
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Where can I find a list of exit codes? (Exit code 64)

I'm receiving an exit code 64 in our batch scheduler (BMC product control-m) executing a PERL script on UX-HP. Can you tell me where I can find a list of exit codes and their meaning. I'm assuming the exit code is from the Unix operating system not PERL. (3 Replies)
Discussion started by: jkuchar747
3 Replies

2. Programming

exit(0) versus exit(1)

What is the difference between using exit(0) and exit(1) to exit a program? Which should I use? (9 Replies)
Discussion started by: enuenu
9 Replies

3. UNIX for Dummies Questions & Answers

what is meaning of exit(0) and exit(1)

can u tell me what is the meaning of exit(0),exit(1),exit(2) what is diff amonng these. Amit (1 Reply)
Discussion started by: amitpansuria
1 Replies

4. UNIX for Dummies Questions & Answers

Grep without returns...

Is there a command where I can pipe my grep into it and it will output it with spaces rather than returns? Example I want to turn prompt$ grep blah file blah blah into this prompt$ grep blah file | someCommand blah blah (1 Reply)
Discussion started by: mrwatkin
1 Replies

5. Shell Programming and Scripting

Grep returns nothing

Hi all, I am trying to grep a .txt file for a word. When I hit enter, it returns back to $ The file is 4155402 in size and is named in this way: *_eveningtimes_done_log.txt I use this command, being in the same directory as the file: grep -i "invalid" *_eveningtimes_done_log.txt ... (16 Replies)
Discussion started by: DallasT
16 Replies

6. Shell Programming and Scripting

Calculation returns no value

#/bin/sh ..... #convert memory to MB let "mmsize_a= ($mmsize)/256" let "mminuse_a= ($mminuse)/256" let "mmfree_a= ($mmsize_a -$mminuse_a)" let "mmfreepercent= (($mmfree_a)/($mmsize_a))*100" # #format output echo "\n\n######################" >>$sndFile echo "\n$sysName Total Memory usage"... (3 Replies)
Discussion started by: Daniel Gate
3 Replies

7. UNIX for Dummies Questions & Answers

Help with Functions and Value returns

mon_yy=${1} date_found=`find_end_day $mon_yy` export_dealer_changes ${date_found} Hello I am trying to pull a formatted date back from the function find_end_day and pass it into the function export_dealer_changes. When I try the above the variable date_found is empty. I have tried various... (3 Replies)
Discussion started by: treemyf
3 Replies

8. Shell Programming and Scripting

Need the difference between exit 1 & exit 7

Hi In one of the script I am seeing some thing like exit 7,exit 1,exit 2,exit 3,exit 9,exit6.What is the difference between all of this exit.Can anyone help here please (3 Replies)
Discussion started by: ginrkf
3 Replies

9. Shell Programming and Scripting

Help in function returns value

Hi, I need to return a value from the function. the value will be the output from cat command which uses random fucntion. #!/bin/ksh hello() { var1=$(`cat /dev/urandom| tr -dc 'a-zA-Z0-9-!%&()*+,-/:;<=>?_'|fold -w 10 | head -n 1`) echo "value is" var1 return var1 } hello var=$?... (2 Replies)
Discussion started by: Nandy
2 Replies
CSS::DOM::Rule::Media(3pm)				User Contributed Perl Documentation				CSS::DOM::Rule::Media(3pm)

NAME
CSS::DOM::Rule::Media - CSS @media rule class for CSS::DOM VERSION
Version 0.14 SYNOPSIS
use CSS::DOM; my $media_rule = CSS::DOM->parse( '@media print { body { background: none } }' )->cssRules->[0]; # OR: use CSS::DOM::Rule::Media; my $media_rule = new CSS::DOM::Rule::Media $parent; push @{$media_rule->media}, 'print'; $media_rule->insertRule('body { background: none }') DESCRIPTION
This module implements CSS @media rules for CSS::DOM. It inherits from CSS::DOM::Rule and implements the CSSMediaRule DOM interface. METHODS
media Returns the MediaList associated with the @media rule (or a plain list in list context). This defaults to an empty list. You can pass a comma-delimited string to the MediaList's "mediaText" method to set it. cssRules In scalar context, this returns a CSS::DOM::RuleList object (simply a blessed array reference) of CSS::DOM::Rule objects. In list context it returns a list. insertRule ( $css_code, $index ) Parses the rule contained in the $css_code, inserting it the @media rule's list of subrules at the given $index. deleteRule ( $index ) Deletes the rule at the given $index. SEE ALSO
CSS::DOM CSS::DOM::Rule CSS::DOM::MediaList perl v5.10.1 2010-12-10 CSS::DOM::Rule::Media(3pm)
All times are GMT -4. The time now is 10:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy