Results 1 to 5 of 5

Thread: Problem of shell script on Linux

  1. #1
    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?

  2. #2
    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.

  3. #3
    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);
    }

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Problem of shell script on Linux

    the main page for POSIX exit () contains

    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.

  5. #5
    Join Date
    May 2008
    Posts
    2,389

    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:

    type file.txt | more

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,142,324.08003 seconds with 16 queries