ssh usrname@ip 'bash -c "for i in 1 2 3; do date;sleep 1;done" '
works well, and here is the output of the said command:
Sun Jun 1 11:02:12 CST 2022
Sun Jun 1 11:02:13 CST 2022
Sun Jun 1 11:02:14 CST 2022
Whereas the command below encounters error:
ssh usrname@ip 'bash -c "for i in $(seq 1 3); do date;sleep 1;done" '
Here is the error message:
bash: -c: line 1: syntax error near unexpected token `2'
bash: -c: line 1: `2'
What confuses is that for i in $(seq 1 3); do date;sleep 1;done works well in local bash or remote bash.
Tips:You can try ssh usrname@ip 'bash -c "for i in 1 2 3; do date;sleep 1;done" ' in your local computer which has sshd service by replacing the ip to your computer.