Receiving " syntax error near unexpected token `then'" from remote Linux server with if, then, fi
2
votes
2
answers
412
views
I need help in determining why I get
syntax error near unexpected token `then'
from the following command:
for vm in {20..30} ; do ssh -q -o "StrictHostKeyChecking no" 192.168.210.${vm} "hostname; echo $password | su - root -c \"\ if $(whoami | grep -q root);then echo Good; else echo Bad;fi \"" ; done
vm201scf001
-bash: -c: line 0: syntax error near unexpected token `then'
-bash: -c: line 0: `\ if ;then echo Good; else echo Bad;fi '
This simple command does work though:
for vm in {20..30} ; do ssh -q -o "StrictHostKeyChecking no" 192.168.210.${vm} "hostname; echo $password | su - root -c \"\uptime \"" ; done
vm201scf001
22:11:41 up 422 days, 3:32, 0 users, load average: 0.28, 0.44, 0.52
Does the if
, then
, fi
statement not work in this case? Please advise.
Asked by Bjoern
(59 rep)
May 9, 2025, 10:17 PM
Last activity: May 12, 2025, 12:23 AM
Last activity: May 12, 2025, 12:23 AM