Results 1 to 6 of 6

Thread: SSH return function

  1. #1
    Join Date
    Mar 2010
    Posts
    197

    SSH return function

    Hello,
    I have a problem with the return command. I have a function that is called function_1 in the hand. In this role, several places of return (if I get an error, I wish to exit this function without function_1 execute to the end). I would now relocate some treatments function_1 a new function, function_2, which will be called into function_1. My question is: if I made a return in function_2 is what I would leave also function_1 (behavior wishes). If not, how can I do? Any help regarding this topic will be helpful. Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    343

    Re: SSH return function

    Hello,
    A prior, if you made a return in fcnt_2, you come back in fcnt_1, you can decide to code a return value for fcnt_2 (genus return 1 if error, 0 otherwise), and test the return value in fcnt_1:
    Code:
    int ret = fcnt_2 (......);
    if (ret == 1) (
         return (the function here) / * and you come back in main * /
    else (
    / * S is smoothly fcnt_2 * /
    .....
    and you have tested every call fcnt_2, there may be simpler, but at least like this, you most effective way of testing your fcnt_2 function.

  3. #3
    Join Date
    Apr 2008
    Posts
    264

    Re: SSH return function

    Hello,
    I do have a similar kind of problem.
    Here is what i am trying
    Code:
    func_1 ()
    (
      command = "command shell has"
      func_2
     
      command = "Shell command b"
      func_2
    
      command = "c shell command"
      func_2
    
       ...
    )
    
    func_2 ()
    (
      if! $ command; Then
        echo "$ command has failed."
        # -> This is where I put a "return" to exit the func_1 ...
      fi
    )
    
    # Main
    
    func_1
    
    ...
    
    Hand # end

  4. #4
    Join Date
    Nov 2009
    Posts
    347

    Re: SSH return function

    Hello,
    See if the following code can help you
    Code:
    #! / Bin / sh
    func2 ()
    (
            $ 1 | | (
                    RET = $?
                    echo "$ 1 was aborted"
                    return $ RET
            )
    )
    
    func1 ()
    (
            func2 echo success' | | return $?
    
            func2 'echoz "failure"' | | return $?
    
            func2 echo vanished '| | return $?
    )
    
    # A "hand" reduced to its simplest expression:
    func1

  5. #5
    Join Date
    Nov 2009
    Posts
    335

    Re: SSH return function

    Hello,
    You can use the & & and | | for chaining of operations:
    Here is what i am saying
    Code:
    command1 & & command2
    command1 is executed, and if the result is zero, command2 is executed otherwise command2 is not.
    Code:
    command1 | | command2
    Conversely, if command1 returns zero, command2 N'SET not executed.

  6. #6
    Join Date
    May 2008
    Posts
    248

    Re: SSH return function

    Hello,
    See if the following code is helpful to you
    Code:
    #! / Bin / sh
    func_1 ()
    (
      cd = "my_command '
      func_2 | | return
    )
    
    func_2 ()
    (
      if! eval $ cd> / dev / null 2> &1; Then
        r = $?
        end_test "NO" "$ cd failed."
        odi_todo = 0
        return $ r
      else
        return 0
      fi
    )
    
    # Main
    func_1

Similar Threads

  1. Is it possible for a function to return two values?
    By hounds in forum Software Development
    Replies: 5
    Last Post: 13-03-2010, 07:51 PM
  2. How can I return different class in one function?
    By Madaleno in forum Software Development
    Replies: 4
    Last Post: 10-02-2010, 09:45 PM
  3. Return string from a function in C
    By Samarth in forum Software Development
    Replies: 3
    Last Post: 28-12-2009, 12:24 PM
  4. How to return an array from function
    By Rilex in forum Software Development
    Replies: 3
    Last Post: 02-10-2009, 09:18 AM
  5. How to return a recordset from a function in ASP
    By Ananias in forum Software Development
    Replies: 3
    Last Post: 19-06-2009, 11:35 PM

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,711,674,886.80308 seconds with 17 queries