Find the answer to your Linux question:
Results 1 to 3 of 3
Why does this not work? I need to return negative numbers from functions No matter which negative number (-1 -5 -10) the function always returns 2 Code: function testfcn{ return ...
  1. #1
    Just Joined!
    Join Date
    Apr 2010
    Posts
    3

    return -1 does not work...?

    Why does this not work?
    I need to return negative numbers from functions
    No matter which negative number (-1 -5 -10) the function always returns 2

    Code:
    function testfcn{
    return -1
    }
    
    testfcn
    echo $? # <- always displays 2
    please help!!!
    regards!

  2. #2
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    I believe that bash can only return values 0 - 255 from functions.
    Make mine Arch Linux

  3. #3
    Linux Engineer RobinVossen's Avatar
    Join Date
    Aug 2007
    Location
    The Netherlands
    Posts
    1,422
    I am not sure about it either.
    But @gerard4143 -1 is 0xFFFFFFFF
    And if bash only support unsigned byte values it would be 255 and not 2.
    New Users, please read this..
    Google first, then ask..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...