1

Following function hangs :

ssh() {
    local RESULTS;
    RESULTS=$(ssh $USERNAME@$SERVER $SSH_COMMAND1);
    echo $RESULTS;
}

ssh;

while if i run following commands they work fine :

    RESULTS=$(ssh $USERNAME@$SERVER $SSH_COMMAND1);
    echo $RESULTS;

Can someone please guide me to the right direction of looking for error?

Amber
  • 121
  • 5

2 Answers2

4

You have a recursive error. You define a function called 'ssh' then call the same function in your function. This results in a recursive loop.

Specify the absolute path to the ssh binary and that should fix it.

Matthew Ife
  • 23,357
  • 3
  • 55
  • 72
0

I just made the same mistake. I think you can also use the command command to run a command (the binary itself) that has the same name as the function, in order to avoid hardcoding the path to the binary:

ssh() {
    local RESULTS;
    RESULTS=$(command ssh $USERNAME@$SERVER $SSH_COMMAND1);
    echo $RESULTS;
}

Though for what you're doing here I do recommend naming the function differently; ssh is a very common command that no one would expect to behave this way!

briantist
  • 2,545
  • 1
  • 19
  • 34