Bash – can’t run remote ssh command without heredoc

bashssh

I can't get this command to work:

user@server:~: ssh otherserver bash -ic 'source .profile; some-aliased-command'

Variations I tried

user@server:~: ssh -t otherserver bash -ic 'source .profile; some-aliased-command'
user@server:~: ssh -t otherserver "bash -ic 'source .profile; some-aliased-command'"
user@server:~: ssh -t otherserver "bash -ic source .profile; some-aliased-command"
user@server:~: ssh otherserver bash -ic 'source .profile; some-aliased-command'
user@server:~: ssh otherserver "bash -ic 'source .profile; some-aliased-command'"
user@server:~: ssh otherserver "bash -ic source .profile; some-aliased-command"

I usually get a variation of these errors:

bash: cannot set terminal process group (-1): Invalid argument
bash:  no job control in this shell
stdin: is not a tty
bash: some-aliased-command: command not found

But like this, it does work:

user@server:~: ssh otherserver bash -i << EOF
source .profile
some-aliased-command
EOF

In fact when I run this:

ssh -t otherserver 'bash -ic "source ~/.profile; alias"'

It lists all the aliases including the some-aliased-command that I want to run.

I tried al sorts of variations with single, double, escaped quoutes, but I am stuck and it will only work with the heredoc version.

How do I make it work without the heredoc ( as a one-liner ) ?

Best Answer

Same answer as previous, but add +m for job control issue fix:

ssh otherserver "bash -ic +m 'source .profile; some-aliased-command'"
Related Question