2

为什么我无法在远程主机上执行命令。我错过了什么吗?

bash 文件:hello.sh

#!/bin/sh 
host_name="myHost"
ssh $host_name  '
STR="Hello World!"
echo $STR
'

executing above file: the print out:
 > ./print_node_status.sh
Enter Windows password: 
STR=Hello World!: Command not found.
STR: Undefined variable.
4

1 回答 1

1

看起来您的远程 shell 是C shell,而不是 Bash。

你有几个选择:

  • 调整您的代码以符合该外壳的语言:

   ssh $host_name  '
   set STR="Hello World\!"
   echo $STR
   '
  • /bin/bash如果可用,请在您的远程进程中执行,例如:

   ssh $host_name  '
   exec /bin/bash
   STR="Hello World!"
   echo $STR
   '
  • 将该节点上用户的默认 shell 更改为/bin/bash,请参见chsh(1)手册页。
于 2017-09-05T07:46:52.000 回答