0

I've been learning the shell with a great tutorial, linuxcommand.org. After a lot of learning and practice with navigating directories, editing files, etc, I've moved on to writing shell scripts.

One of the first tutorials linuxcommand.org has is using HTML in a shell script to return some system info. You can check it out here . I'm currently on the 'Command Substitution and Constants' section.

One of the first things in the tutorial said the file could be used by redirecting the standard output to .html:

~me$ ./sysinfo_page > sysinfo_page.html

my script looks exactly like the one on the link, but I'll post it anyway:

(the only difference is linux uses the env var $HOSTNAME, I'm on OS X and it's $LOGNAME)

#!/bin/bash

# sysinfo_page - Generate an HTML page based on system information

title="My System Information"
RIGHT_NOW=$(date +"%x %r %Z")
TIME_STAMP="Updated on $RIGHT_NOW by $USER"

cat <<- _EOF_
    <html>
    <head>
        <title>
        $title $LOGNAME
        </title>
    </head>

    <body>
        <h1>$title $LOGNAME</h1>
        <p>$TIME_STAMP</p>
    </body>
    </html>
_EOF_

When I type into the command line:

~me$ ./sysinfo_page

it gives me the contents of only the HTML, but it isn't formatted and still displays the tags. I'm assuming that by redirecting the standard output to a .html extension would give me the formatted HTML page, without the tags but I wouldn't know because, after giving chmod rwx permission with 755, I type:

~$me ./sysinfo_page.html

And get this error:

./sysinfo_page.html: line 1: syntax error near unexpected token `newline'
./sysinfo_page.html: line 1: `<html>'

I understand by what I've read that < > indicates a placeholder, but that's the HTML syntax...and exactly how it works on the tutorial. I thought maybe adding a <!DOCTYPE> would fix it, but didn't. My question is, what am I doing wrong here? How can I get it to display the HTML page correctly?

3

HTML is not a script, it's a markup language. You need a browser to render HTML. To view it, you probably want

open sysinfo_page.html
  • wow I'm such a noob. I know HTML isn't a script, but I thought since in this case it was contained in a shell script, the env vars wouldn't be accessed. Guess I was wrong. Thanks! – samrap Sep 12 '13 at 19:01
0

Wrapping your HTML markup in single quotes should allow you to run it directly in the terminal without error though it just shows you the markup and that defeats the purpose of using HTML.

Using open as stated by glenn is probably what you want.

  • yea I mean I could even just view the file in less and it gives the same result as using single quotations. – samrap Sep 12 '13 at 19:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .