Unix/Linux Go Back    


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

Handling negative return code value in ksh

UNIX for Advanced & Expert Users


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 06-06-2002
emilia emilia is offline
Registered User
 
Join Date: Jun 2002
Last Activity: 2 May 2003, 5:19 PM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Unix or Linux Question Handling negative return code value in ksh

I am running a third party program from within a korn shell script (aix 5.1).
The program returns zero, positive and negative return code values but the negative ones are represented as positive integers in the $? return code variable. For example -1 becomes 255, -2 becomes 254 etc.

My script needs to convey these return codes (to a calling process) as a true negative value (ie a value that that will actually test negative). Is there any way to do this (preferably within a shell script) ?

I hope someone can help

With Thanks

Emilia

Report this post to a moderator | IP: Logged
Sponsored Links
    #2  
Old Unix and Linux 06-06-2002
Perderabo's Unix or Linux Image
Perderabo Perderabo is offline Forum Staff  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 7 April 2015, 12:31 PM EDT
Location: Ashburn, Virginia
Posts: 9,931
Thanks: 64
Thanked 446 Times in 263 Posts
You gotta remember that the return code is only a byte. There are only 256 different values that can be returned. And negative return codes are not a great idea because of this. But if you can be sure that the return code is in the range -127 to 128, then you can do something like:

third.party.program
retcode=$?
((retcode > 128)) && ((retcode=retcode-256))
echo $retcode
Sponsored Links
    #3  
Old Unix and Linux 06-07-2002
emilia emilia is offline
Registered User
 
Join Date: Jun 2002
Last Activity: 2 May 2003, 5:19 PM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
MySQL

Perderabo,

Many thanks for your reply.
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem with implementing the times() function in C (struct tms times return zero/negative values) g_p Programming 1 10-31-2011 04:04 PM
Problem with call of Java Programm & return code handling & output to several streams. danifunny Shell Programming and Scripting 2 05-18-2011 07:32 AM
Handling return & exit statements Ariean UNIX for Dummies Questions & Answers 10 08-02-2010 04:56 PM
Gen. Question - Script calls multiple programs - Return Code Handling? jnanasakti Shell Programming and Scripting 1 11-05-2008 01:27 PM
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



All times are GMT -4. The time now is 12:54 AM.