Task:

  1. Variable contains at the end of $$

     $ a='SYS_$$' $ echo $a SYS_$$ 
  2. Here, $$ expands at the end of the line as a process number, and you need to display the string "SYS_$$" , which is passed as a parameter.

     $ echo "echo \$1" | ssh another_host "/bin/sh -s $a" SYS_18992 
  • use single quotes for echo - KoVadim
  • Single quotes did not help: my_host: $ echo 'echo \ $ 1' | ssh another_host "/ bin / sh -s $ a" $ 1 my_host: rman: $ echo 'echo $ 1' | ssh another_host "/ bin / sh -s $ a" SYS_26315 - mushbaraka mushbaraka

2 answers 2

Try this:

 $ a='SYS_$$' $ echo 'echo $1' | ssh another_host "/bin/sh -s '$a'" SYS_$$ 
  • When you call ssh , inside double quotes, single quotes tether their special purpose and the variable will be replaced with its value, i.e. $SYS_$$ .

  • Further, when calling sh on a remote host, single quotes again acquire their special purpose and prevent $$ from being replaced with the current pid .

  • Thank! That helped! What you need! - mushbaraka mushbaraka
  • No, it still did not help: my_host: $ a = SYS _ $$$ my_host: $ echo 'echo $ 1' | ssh another_host "/ bin / sh -s '$ a'" SYS_8847608 $ - mushbaraka mushbaraka
  • Here - a = SYS _ $$$ - where are the quotes gone? - 0xdb
  • yes, for sure, I was wrong .. it works - mushbaraka mushbaraka
  • Well, do not forget to mark the answer of Barakin as accepted. - 0xdb

you must pass single quotes around the argument with which the sh program is called. for this you need to add the characters \ :

 $ v='a$$'; echo 'echo $1' | ssh хост sh -s \'$v\' a$$