0

I have a script test.sh and I am trying to ssh and call that scrip't function in the same script:

#!/bin/sh

testme()
{
   echo "hello world"
}

ssh myserver "/opt/scripts/test.sh; testme"

But I keep getting testme command not found

What is the correct way of calling a function from a script after ssh?

codec
  • 6,576
  • 18
  • 63
  • 115

1 Answers1

1

If you use Bash on both sides, you can have it serialize the function for you:

#!/bin/bash

testme()
{
   echo "hello world"
}

ssh myserver "$(declare -f testme); testme"

If you need sh compatibility, this is not an option.

that other guy
  • 109,738
  • 11
  • 156
  • 185