I have a function that needs to be sourced when I connect with my server in a non-interactive shell but it seems that no place fits.
I would like to be able to do this
ssh user@remote.com 'my_function'
I read Why does an SSH remote command get fewer environment variables then when run manually? and found that if I put a variable (like hi='hello') in my ~/.ssh/environment file I was able to do this
ssh user@remote.com 'echo ${hi}'
and it would echo my 'hello' value and I was a little bit happy; however, I am not able to put function into the ~/.ssh/environment file since it is not that kind of file :)
Now, where can I put my
function hi {
echo 'this is a function'
}
so that it will be sourced during a non-interactive shell?
then I could do
ssh user@remote 'hi'
and it would output 'this is a function'