Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 16-04-2009
Member
 
Join Date: Nov 2008
Posts: 1,221
Problem of shell script on Linux

I would like to write a small program that enables me to read a value that can be between 0 and 1FFF then use it in a shell-script.

Unfortunately, I just discovered that the return code of an executable Linux can not exceed 255. I am especially surprised that the return type of main is an int.

Code:
int main() {
return 257;
}
gives me:
Code:
#echo $?
#1
Why this limitation? And-a-there a way to override?
Reply With Quote
  #2  
Old 16-04-2009
XSI XSI is offline
Member
 
Join Date: May 2008
Posts: 271
Re: Problem of shell script on Linux

It depends on the system and shell. Usually, you recover 8 bits signed or not, depending. Do not rely on it for too large values.
Reply With Quote
  #3  
Old 16-04-2009
Member
 
Join Date: Feb 2008
Posts: 194
Re: Problem of shell script on Linux

To retrieve more information, one solution is to write to a file or to stdout, which is quite handy if you use a pipe then.

Code:
# include <stdlib.h>
# include <stdio.h>
int main (void)
{
  /* Write to standard output
      (not bothered to open or close "stdout") */
   fprintf (stdout, "12345");
   return (0);
}
Reply With Quote
  #4  
Old 16-04-2009
Member
 
Join Date: Jan 2008
Posts: 1,515
Re: Problem of shell script on Linux

the main page for POSIX exit () contains

Quote:
The value of status may be 0, EXIT_SUCCESS, EXIT_FAILURE, or any other value, though only the least significant 8 bits (that is, status & 0377) shall be available to a waiting parent process.
Reply With Quote
  #5  
Old 16-04-2009
Member
 
Join Date: May 2008
Posts: 2,383
Re: Problem of shell script on Linux

256 values for a shell that is more than enough to take decisions (in practice, it is 0 (OK) or 1 (ERROR)). If you need to return a specific value (text), uses a text file. It can then be read by the application who needs it.

You can also get the value for stdout and stdin recover directly from another application using the 'pipe' (usually '|' in the current system ...)

Use classic MS-DOS:

Quote:
type file.txt | more
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Problem of shell script on Linux"
Thread Thread Starter Forum Replies Last Post
Linux shell script to find duplicate images Savious Operating Systems 6 21-10-2010 05:26 AM
shell script SSH not working Lilya Software Development 9 16-10-2010 01:53 AM
Shell script with sed Ameeryan Software Development 5 23-12-2009 02:29 PM
Linux Shell Script to make CD/DVD Image mounting possible kelfro Software Development 2 04-03-2009 03:18 PM
Shell script Problem in JAVA programing Pandya Software Development 3 04-03-2009 08:26 AM


All times are GMT +5.5. The time now is 03:46 PM.