Why I cannot execute command on remote host. Do I miss something?
Bash file: 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.
It looks like your remote shell is the C shell, not Bash.
You have several options:
/bin/bash
in your remote process, if it is available, e.g.:/bin/bash
, see thechsh(1)
manpage.