Code help create img html tags with printf
Hello LQ fans
I need help in correcting the proper syntax for printf to create basic img tags. I have five images and I want printf to create img src tags for each one of them. I want it to look like this. <img src="image1.jpg"> <img src="image2.jpg"> <img src="image3.jpg"> <img src="image4.jpg"> <img src="image5.jpg"> Here is the code I am struggling with. Code:
for i in *.jpg; do echo printf \<img src="%s>\n" "$i"; done Quote:
I appreciate any help with this code. Thanks |
I solved it by using this code after experimenting.
Code:
for i in *.jpg; do echo "<img src=\"$i\">"; done <img src="image2.jpg"> <img src="image3.jpg"> <img src="image4.jpg"> <img src="image5.jpg"> However, I'm new to the printf command. I still would like to know if printf can do what I wanted in my first post. |
The code in your printf was somewhat mixed up.
Code:
for i in *.jpg; do printf "<img src=%s>\n" "$i"; done |
Quote:
Quote:
Code:
for i in *.jpg; do printf "<img src=\"%s\">\n" "$i"; done Quote:
+1 |
or even:
Code:
for i in *.jpg; do printf '<img src="%s">\n' "$i"; done |
Quote:
Thanks |
Hopefully they don't, put if a haxor created a file called a"b.jpg, you would get a HTML-syntax error.
|
Quote:
http://www.littlewebhut.com/html/img_tag/ |
True, but unrelated. I'll try again. Say you have these four files:
Code:
a.b.jpg Edit: this works in newer shells: Code:
for i in *.jpg; do Code:
for i in *.jpg; do |
All times are GMT -5. The time now is 02:16 AM. |