I can run the followind loop locally
for i in A B C; do mycommand $i; done
Now I am trying to send it over ssh
The following version
ssh myhost for i in A B C; do mycommand $i; done
The following version
ssh myhost "for i in A B C; do mycommand $i; done"
also fails, because it wants i
varibale locally.
How to handle?
Is there any general approach, for example, what if mycommand
is another ssh?
ssh myhost 'for i in hos1 host2 host3; do ssh "$i" ... another for expression
$command_line_built_by_ssh
, you need to understand, predict and mastermind the parsing and interpreting that happens before. You need to craft your local command, so after the local shell andssh
digest it, it becomes the exact$command_line…
you want to execute on the remote side." – Kamil Maciorowski Feb 21 '23 at 14:31