for loop - Execute a local bash variable inside double quotes -
hypothetically have 4 webservers need add line of html file. can see need integer appear after cluster=
for in 01 02 03 04; ssh web.${i}.domain.com 'echo "<img src=beacon.gif?cluster=${i}>" >> /var/www/index.html'; done how can accomplished? in advance.
please note ' before , after ${i}:
for in 01 02 03 04; ssh web.${i}.domain.com 'echo "<img src=beacon.gif?cluster='${i}'>" >> /var/www/index.html' done edit: there huge difference between quoting in shell , string literals in programming languages. in shell, "quoting used remove special meaning of characters or words shell" (bash manual). following lines identical bash:
'foo bar' foo' 'bar there no need quote alphabetic characters - enhances readability. in case, special characters " , < must quoted. variable $i contains digits, , substitution can safely done outside of quotes.
Comments
Post a Comment