This question already has an answer here:

I want to do some script on a remote mashine through ssh:

ssh Server  "V=\$\(lua -e 'print\(require\(\\\"platform_info\\\"\).get_image_name\(\)\)'\); echo \$V"

But this echo $V at the end gives me no output.

I tried a lot of different masking with backslashes, but I cannot get this right.

How do I mask the command correctly and get the output of the lua command?

marked as duplicate by Barmar, sorontar, Satō Katsura, thrig, Thomas Nyman Mar 18 '17 at 17:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • You can't escape quotes inside a single-quoted string. – Barmar Mar 17 '17 at 21:20
  • @Barmar: I edited it to a try with double quotes, but still I must have a tiny error here still – rubo77 Mar 17 '17 at 21:41
  • Nesting quotes in the shell is very tricky. Did you look at the duplicate question? – Barmar Mar 17 '17 at 21:45
  • @Barmar I tried with HEREDOC but that only writes out the code directly instead of executing it on the target – rubo77 Mar 17 '17 at 21:53
  • Often the best way to solve this is to put the code in a script on the remote machine, and then just execute the script with ssh. – Barmar Mar 17 '17 at 22:11
ssh Server 'V=$(lua -e "print(require(\"platform_info\").get_image_name())");echo "$V";'

I am not familiar with lua, but what I would do is first try to run the lua command on the local m/c and observe the quoting. Then place everything in single quotes '...' and then look at other stuff. HTH

  • this still seems wrong: sh: 1: lua: not found – rubo77 Mar 17 '17 at 22:59
  • Then set your PATH straight first before diving into the quotes. – user218374 Mar 17 '17 at 23:03
  • Why the PATH. the same problem with the full path: sh: 1: /usr/bin/lua: not found. I think your command will start the lua command on my machine and not on the target. – rubo77 Mar 17 '17 at 23:06
  • 1
    That means /usr/bin/lua does not exist on the remote m/c. You need to first investigate where on the remote m/c is this utility located. – user218374 Mar 17 '17 at 23:08
  • Sure that exists there. The command works on the server. I don't have lua on my laptop – rubo77 Mar 18 '17 at 5:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.