Command not found.when executing bash on remote host

1.4k Views Asked by At

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.
1

There are 1 best solutions below

0
On

It looks like your remote shell is the C shell, not Bash.

You have several options:

  • Adapt your code to conform to that shell's language:

   ssh $host_name  '
   set STR="Hello World\!"
   echo $STR
   '
  • Execute /bin/bash in your remote process, if it is available, e.g.:

   ssh $host_name  '
   exec /bin/bash
   STR="Hello World!"
   echo $STR
   '
  • Change the default shell of your user on that node to /bin/bash, see the chsh(1) manpage.