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:
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:
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?