heredocがないとリモートSSHコマンドを実行できません

heredocがないとリモートSSHコマンドを実行できません

このコマンドは機能しません。

user@server:~: ssh 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 -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"

通常、次のようなさまざまなエラーが発生します。

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

しかし、実際には次のように動作します。

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

実際にこれを実行すると、次のようになります。

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

some-aliased-command私が実行したいエイリアスを含むすべてのエイリアスが一覧表示されます。

一重引用符、二重引用符、エスケープされた引用符のさまざまなバリエーションを試しましたが、ブロックされました。 heredocバージョンでのみ機能します。

heredocなしで(1行のコードで)どのように機能させますか?

ベストアンサー1

以前の答えと同じですが、タスク+m制御の問題を修正しました。

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

おすすめ記事