Handling negative return code value in ksh | Unix Linux Forums | UNIX for Advanced & Expert Users

  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 Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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
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 06-06-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 24 November 2014, 10:48 PM EST
Location: Ashburn, Virginia
Posts: 9,930
Thanks: 64
Thanked 438 Times in 261 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 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 Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 05:04 PM
Problem with call of Java Programm & return code handling & output to several streams. danifunny Shell Programming and Scripting 2 05-18-2011 08:32 AM
Handling return & exit statements Ariean UNIX for Dummies Questions & Answers 10 08-02-2010 05:56 PM
Gen. Question - Script calls multiple programs - Return Code Handling? jnanasakti Shell Programming and Scripting 1 11-05-2008 02: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 07:44 AM



All times are GMT -4. The time now is 09:19 AM.