difficult to understand how this code works
This is tricky way to combine two scripts written in two different languages. We call it here "hybrid". Let me explain it step by step
Code: Select all
: << '____CMD____'
@echo off
ssh "%~f0" %*
goto :eof
____CMD____
pwd
ls
The major trick is that this script will be processed twice by the
cmd.exe and
bash/ssh. The script is constructed so the most of the commands are valid from perspective of batch and bash.
The first processor is cmd.exe. It parses the file and executes the first 4 lines of the file:
A.1. the first character is colon is interpreted as a label and does nothing
A.2. turn off echoing in batch
A.3. the real invocation of bash or ssh passing the same arguments
A.4. stop executing the script and the further parsing of this file
The second processor is bash or ssh invoked on the step A.3 above:
B.1. the first line is the empty command (the colon is interpreted as empty command) taking HEREDOC (the multiple line argument) which beginning and end are marked with the ____CMD____ string. This allows us to avoid the interpretation of batch commands.
B.2 So the rest of the file is assumed as the valid bash script.
As the conclusion. The first 5 lines are so called prolog or glue between two different worlds (batch and bash). What you need is to leave it "as is" and put the bash commands below it. One thing you could do is to replace "ssh" with the command you need "plink -m".
Could you let us know which one of three suggested options does work for you?