0

Normally when the output of a command is sent to a string in bash the following syntax is used:

variable="$(command)"

How do I do the same in a ssh query? Because doing something like

ssh user@address bash -c "'
variable="$(command)"
'"

seems to record nothing into the variable.

  • 1
    What do you *actually* want to accomplish? Should the command whose output is assigned be run locally, or remotely? Do you want the *assignment* to be local or remote? Showing how you're testing what is or isn't in the variable would clarify some of this. – Charles Duffy Apr 05 '18 at 23:45
  • BTW, `command` is actually the name of a built-in command (POSIX sh specifies a command named `command`!), so it's not a great choice of placeholders. – Charles Duffy Apr 05 '18 at 23:46
  • ...I added two very different duplicates to cover both the potential interpretations of this question. In the future, trying to include a [mcve] would avoid such ambiguity. – Charles Duffy Apr 05 '18 at 23:49
  • Basically, I have a script that will log into another computer and execute some extra commands remotely by taking values of local variables that will be passed via ssh. – Ícaro Lorran Apr 05 '18 at 23:53
  • so, the easy way to use *local* variables remotely is to pass them on the command line, after creating safely-escaped versions. We do already have questions covering this; let me make sure the duplicate list includes them. – Charles Duffy Apr 05 '18 at 23:59
  • ...added https://stackoverflow.com/questions/37103664/passing-a-variable-to-a-remote-host-in-a-bash-script-with-ssh-and-eof to the list, which is directly on-point. – Charles Duffy Apr 06 '18 at 00:00

0 Answers0