Sponsored Content
Top Forums Shell Programming and Scripting Writing HTML with variables from an array or other means Post 302805015 by tntelle on Thursday 9th of May 2013 02:03:35 PM
Old 05-09-2013
Writing HTML with variables from an array or other means

Hello!

I wish to create a script that will automate the creation of HTML files...

for example, if my HTML starts out containing:

Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>$TITLE</title>
</head>

I want to put that into something that I can read and write later on. My idea was to put that into an array, then call it like so:

Code:
HTML_HEADER=(
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>$TITLE</title>
</head>
)

Then later:
Code:
TITLE=1Fish2Fish

for z in "${HTML_HEADER[@]}"
do
echo "z" >> OUTPUT.HTML
done


This doesn't work, as there are quotes and other characters I assume will be mis-interpreted by bash.

I want to be able to write the HTML lines without having to escape quotes and other characters and as my HTML changes, I want to make it simple for me to just drop in the modified HTML code into the array.

Please let me know if there is an easy way to go about this, or if what I am trying to accomplish does not make sense.

Thank you in advance!Smilie

Last edited by Scrutinizer; 05-09-2013 at 03:50 PM.. Reason: code tags
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Writing to variables within a loop

I have a loop which will go round "i" number of times and return a value each time. Is there a way to set a variable(i) such that I will end up with variable(1), variable(2), variable(3) etc. for however many times the loop went round? eg: for (i=1;i<=3;i++) --do some sums--... (0 Replies)
Discussion started by: Sniper Pixie
0 Replies

2. UNIX for Dummies Questions & Answers

Writing variables into a new file

echo "Please enter your surname\n" echo "followed by your first name:\c" read name1 name2 echo "Thank you" echo "Now please enter your age" read age echo "Thanks again, we're nearly done. Please enter your town of birth" read town echo "Hi there $name2 $name1" sleep 3 echo "erm..." sleep... (6 Replies)
Discussion started by: phproxy
6 Replies

3. UNIX for Advanced & Expert Users

Writing into shared memory Array

Hi All, How do I write into shared memory blocks using multiple threads? For example, I have created 50 threads to write into shared memory and 50 threads to read from shared memory. I have already created a shared memory and I want to write into shared memory as follows: ... (0 Replies)
Discussion started by: kumars
0 Replies

4. Shell Programming and Scripting

Converting html table data into multiple variables.

Hi, Basically what I am trying to do is the following. I have created a shell script to grab timetabling information from a website using curl then I crop out only the data I need which is a table based on the current date. It leaves me with a file that has the table I want plus a small amount... (2 Replies)
Discussion started by: domsmith
2 Replies

5. Ubuntu

Fetch html page convert to pdf automatically via cmd or other means, shortcut

Hi, Im used to compiling when i stumble upon some interesting topics in the net and convert it into pdf files unto my HD for future reference's. I using the chrome print to pdf procedure since firefox html to pdf don't work correctly. I just wonder in someone do same thing and did it in a easy... (3 Replies)
Discussion started by: jao_madn
3 Replies

6. Shell Programming and Scripting

Writing html to a file with echo

Hi, I'm having an issue with echo again. I keep getting errors and no file content with these commands in a script. --------------------------------------------------- #!/bin/bash WEBSITE=http://www.google.com touch test1.txt echo "replace("<body>","<body><iframe... (2 Replies)
Discussion started by: digitalviking
2 Replies

7. UNIX for Dummies Questions & Answers

Writing an HTML file in perl

I'm writing a perl script that writes an html file. use Tie::File; my ($dir) = @ARGV; open (HTML,">","$dir/file.html") || die $!; #-----Building HTML file--------------------------- print HTML "<!DOCTYPE html> <html> <head> <title>Output</title> <link... (3 Replies)
Discussion started by: jrymer
3 Replies

8. Shell Programming and Scripting

Need help writing array for the specific need of shell script

I need shell script for the following specfic need, I'll get following output after running my program. I wanted every 50th row in the coloumn and take into array. For example input ============== 03 03 03 03 05 05 05 05 07 07 07 07 I wanted to extract 3,5,7 and store it in... (12 Replies)
Discussion started by: JITHENDER
12 Replies

9. Programming

Writing a Targa file not working from an array

Hello, I wrote code that generates an image that writes its contents to a Targa file. Due to modifications that I wish to do, I decided to copy the value of each pixel as they are calculated to a dynamically allocated array before write it to a file. The problem is now that I all I see is a big... (2 Replies)
Discussion started by: colt
2 Replies
HTML::ElementRaw(3pm)					User Contributed Perl Documentation				     HTML::ElementRaw(3pm)

NAME
HTML::ElementRaw - Perl extension for HTML::Element(3). SYNOPSIS
use HTML::ElementRaw; $er = new HTML::ElementRaw; $text = '<p>I would like this &nbsp; HTML to not be encoded</p>'; $er->push_content($text); $h = new HTML::Element 'h2'; $h->push_content($er); # Now $text will appear as you typed it, non-escaped, # embedded in the HTML produced by $h. print $h->as_HTML; DESCRIPTION
Provides a way to graft raw HTML strings into your HTML::Element(3) structures. Since they represent raw text, these can only be leaves in your HTML element tree. The only methods that are of any real use in this degenerate element are push_content() and as_HTML(). The push_content() method will simply prepend the provided text to the current content. If you happen to pass an HTML::element to push_content, the output of the as_HTML() method in that element will be prepended. REQUIRES
HTML::Element(3) AUTHOR
Matthew P. Sisk, <sisk@mojotoad.com> COPYRIGHT
Copyright (c) 1998-2010 Matthew P. Sisk. All rights reserved. All wrongs revenged. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
HTML::Element(3), HTML::ElementSuper(3), HTML::Element::Glob(3), HTML::ElementTable(3), perl(1). perl v5.10.1 2010-06-09 HTML::ElementRaw(3pm)
All times are GMT -4. The time now is 01:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy