-
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.
-
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.
-
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
-
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
-
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.
-
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
Page generated in 1,713,575,263.00933 seconds with 11 queries