我使用 shell 脚本运行 R 程序,如下所示:
host_list="server@com" Directory="/home/program/" ssh -f "$host_list" 'cd $Directory && nohup Rscript L_1.R> L_1_sh.txt'
但它总是说
Directory: Undefined variable.
最佳答案
SSH 不会传播所有环境变量。您只是在本地客户端 ssh
程序的环境上进行设置,而不是在服务器端进行设置。作为一种破解,只需将其粘贴到 ssh
远程运行的命令中,而不是预命令环境设置中。
host_list="server@com" ssh -f "$host_list" 'Directory="/home/program/"; cd "$Directory" && nohup ...'
这是该命令的一个简单版本,您可以在不依赖于特定程序设置的情况下对其进行测试。
ssh localhost Dir="/etc"; echo Dir is "$Dir"; cd "$Dir" && pwd && ps
关于linux - 使用 ssh 在 shell 脚本中 undefined variable ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29814961/