5

I try to send command via ssh which looks like this:

ssh user@192.168.1.1 "echo $(uname -a)"

But my problem is, that $(uname -a) part actually create a subshell and executes not on 192.168.1.1 server, but on my system, from which I executed this command.

How can I fix it?

P.S. My actual example involved docker stop all command, which looks like

docker stop $(docker ps -q)

but I simplified question.

UPDATED: Sorry, I oversimplify my question. My command use Here Document (because inside command is complex and use a lot of different quotes marks)

ssh user@192.168.1.1 <<SSHCOMMAND
  echo $(uname -a)
SSHCOMMAND

So Ignacio Vazquez-Abrams solution will not work

ShockwaveNN
  • 2,227
  • 2
  • 29
  • 56

2 Answers2

7

Single quotes suppress all substitution.

ssh user@192.168.1.1 'echo $(uname -a)'
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
6

I found solution -

ssh user@192.168.1.1 <<'SSHCOMMAND'
  echo $(uname -a)
SSHCOMMAND

Pretty strange for me, but works, thanks Ignacio Vazquez-Abrams for correct name of this process 'substitution', I couldn't find before :)

Community
  • 1
  • 1
ShockwaveNN
  • 2,227
  • 2
  • 29
  • 56