I can't find an exit in your code snippet. Assuming you run through the entire code, and leave it with the last line shown, it's obvious it returns 0 as the last echo succeeds.
If you ask yourself why your finds always output a success, look at the RETVAL variable: it's set by the exit code of an obscure command run before the entry into your code snippet.
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:
/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:
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)
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)
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)
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)
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)
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)