如何通过 SSH 运行 一个 shell 脚本,使远程计算机的环境与本地计算机的环境相似?

How can I run a shell script via SSH such that the environment of the remote computer is similar to that of the local computer?

我欢迎重新表述我的问题,因为我不确定这个问题到底叫什么。

我正在尝试使用以下形式的命令通过 SSH 运行 shell 脚本:

ssh -o StrictHostKeyChecking=no lxplus0035 "cd ~/test; bash script1.sh"

当我这样做时,复杂的脚本 script1.sh 因许多语法错误、操作数错误和其他错误而中断。举例如下:

stty: standard input: Invalid argument

当 运行 直接在本地系统和远程系统(在 SSH 会话中连接时)而不是通过 SSH 时,脚本工作正常。为什么通过 SSH 执行脚本会导致这些问题?

stty 问题与您的环境无关,这是 SSH 命令没有为您分配 TTY (What is Pseudo TTY-Allocation? (SSH and Github)) 的结果。为 ssh 添加 -t 参数应该可以解决它。

更多信息: