Here Scripts. Writing An HTML File With A Script

Similar documents
Variables. #!/bin/bash. # sysinfo_page - A script to produce an HTML file. cat <<- _EOF_ <html> <head> <title> My System Information </title> </head>

Bash print to stderr

Chapter 2, Part I Introduction to C Programming

Using bash. Administrative Shell Scripting COMP2101 Fall 2017

I/O and Shell Scripting

24 Writing Your First Script

5/20/2007. Touring Essential Programs

Linux Shell Scripting. Linux System Administration COMP2018 Summer 2017

CMPS 12A Introduction to Programming Lab Assignment 7

My Favorite bash Tips and Tricks

UNIX II:grep, awk, sed. October 30, 2017

A shell can be used in one of two ways:

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1

Lesson 3 Transcript: Part 2 of 2 Tools & Scripting

Review of Fundamentals

CS 25200: Systems Programming. Lecture 10: Shell Scripting in Bash

Essential Linux Shell Commands

Introduction to JAVA

Introduction, Notepad++, File Structure, 9 Tags, Hyperlinks 1

1. Hello World Bash Shell Script. Last Updated on Wednesday, 13 April :03

Programming Fundamentals

Bash scripting Tutorial. Hello World Bash Shell Script. Super User Programming & Scripting 22 March 2013

Programming for Engineers Introduction to C

Utilities. September 8, 2015

Midnight Commander. Features.

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

COMS 6100 Class Notes 3

Lesson 1: Writing Your First JavaScript

5/8/2012. Exploring Utilities Chapter 5

Topic 2: More Shell Skills

A Big Step. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

Title:[ Variables Comparison Operators If Else Statements ]

Week - 01 Lecture - 04 Downloading and installing Python

Web Design Course Syllabus and Course Outline

Makefile Brief Reference

Scripting. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

Fundamentals of Programming. Lecture 3: Introduction to C Programming

Specification-Based Testing 1

CS 307: UNIX PROGRAMMING ENVIRONMENT FIND COMMAND

Lab 4: Shell Scripting

SHELL SCRIPTING: HOW TO AUTOMATE COMMAND LINE TASKS USING BASH SCRIPTING AND SHELL PROGRAMMING BY JASON CANNON

COMP 2718: Shell Scripts: Part 1. By: Dr. Andrew Vardy

Bourne Shell Reference

Open up a terminal, make sure you are in your home directory, and run the command.

12.1 UNDERSTANDING UNIX SHELL PROGRAMMING LANGUAGE: AN INTRODUCTION Writing a Simple Script Executing a Script

Sub-Topic 1: Quoting. Topic 2: More Shell Skills. Sub-Topic 2: Shell Variables. Referring to Shell Variables: More

S E C T I O N O V E R V I E W

Examples: Directory pathname: File pathname: /home/username/ics124/assignments/ /home/username/ops224/assignments/assn1.txt

C Shell Tutorial. Section 1

Topic 2: More Shell Skills. Sub-Topic 1: Quoting. Sub-Topic 2: Shell Variables. Difference Between Single & Double Quotes

bash Args, Signals, Functions Administrative Shell Scripting COMP2101 Fall 2017

Topic 2: More Shell Skills

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

Python Class-Lesson1 Instructor: Yao

Starting to Program in C++ (Basics & I/O)

PHP and MySQL for Dynamic Web Sites. Intro Ed Crowley

Shell scripting Scripting and Computer Environment - Lecture 5

Introduction to Computer Programming CSCI-UA 2. Review Midterm Exam 1

Bashed One Too Many Times. Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009

More Scripting Techniques Scripting Process Example Script

CSCI 211 UNIX Lab. Shell Programming. Dr. Jiang Li. Jiang Li, Ph.D. Department of Computer Science

Command Interpreters. command-line (e.g. Unix shell) On Unix/Linux, bash has become defacto standard shell.

UNIX files searching, and other interrogation techniques

1. What statistic did the wc -l command show? (do man wc to get the answer) A. The number of bytes B. The number of lines C. The number of words

A Brief Introduction to the Linux Shell for Data Science

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

Introduction to Computer Programming in Python Dr. William C. Bulko. Data Types

-n Do not output the trailing new line. -e Enable interpretation of the following backslash escaped characters in the strings:

Introduction to Linux

CSCI 2132: Software Development

The student should be familiar with classes, boolean and String fields, relational operators, parameters and arguments.

Subcontractors. bc math help for the shell. interactive or programatic can accept its commands from stdin can accept an entire bc program s worth

COP4342 UNIX Tools Assignment #3: A Simple Unix Shell. Instructor: Dr. Robert Van Engelen Teaching Assistant: Imran Chowdhury Spring 2018

About this course 1 Recommended chapters... 1 A note about solutions... 2

Laboratory Assignment #3 Eclipse CDT

There are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu)

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

Lecture 3 (02/06, 02/08): Condition Statements Decision, Operations & Information Technologies Robert H. Smith School of Business Spring, 2017

Lecture 3. Input, Output and Data Types

Lab 7c: Rainfall patterns and drainage density

CS Unix Tools & Scripting Lecture 7 Working with Stream

Windshield. Language Reference Manual. Columbia University COMS W4115 Programming Languages and Translators Spring Prof. Stephen A.

Lesson 4 - Basic Text Formatting

3 The Building Blocks: Data Types, Literals, and Variables

PESIT Bangalore South Campus

Here redirection. Case statement. Advanced Unix Tools Lecture 6 CS214 Spring 2004 Friday March 5, 2004

BEGINNER PHP Table of Contents

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

An Illustrated Guide to Shell Magic: Standard I/O & Redirection

Hello, World! An Easy Intro to Python & Programming. Jack Rosenthal

(Refer Slide Time: 01:40)

PYTHON. Values and Variables

IT441. Network Services Administration. Perl: File Handles

CS Unix Tools & Scripting

Implementation of a simple shell, xssh

Regex, Sed, Awk. Arindam Fadikar. December 12, 2017

Shell Programming Systems Skills in C and Unix

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Should you know scanf and printf?

Transcription:

Here Scripts Beginning with this lesson, we will construct a useful application. This application will produce an HTML document that contains information about your system. I spent a lot of time thinking about how to teach shell programming, and the approach I have chosen is very different from most others that I have seen. Most favor a systematic treatment of shell features, and often presume experience with other programming languages. Although I do not assume that you already know how to program, I realize that many people today know how to write HTML, so our program will produce a web page. As we construct our script, we will discover step by step the tools needed to solve the problem at hand. Writing An HTML File With A Script As you may know, a well formed HTML file contains the following content: <html> http://linuxcommand.org/lc3_wss0030.php 1/8

The title of your page Your page content goes here. </html> Now, with what we already know, we could write a script to produce the above content: # sysinfo_page - A script to produce an html file echo "<html>" echo "" echo " " echo " The title of your page" echo " " echo "" echo "" echo "" echo " Your page content goes here." http://linuxcommand.org/lc3_wss0030.php 2/8

echo " Your page content goes here." echo "" echo "</html>" This script can be used as follows: [me@linuxbox me]$sysinfo_page > sysinfo_page.html It has been said that the greatest programmers are also the laziest. They write programs to save themselves work. Likewise, when clever programmers write programs, they try to save themselves typing. The first improvement to this script will be to replace the repeated use of the echo command with a single instance by using quotation more efficiently: # sysinfo_page - A script to produce an HTML file echo "<html> http://linuxcommand.org/lc3_wss0030.php 3/8

The title of your page Your page content goes here. </html>" Using quotation, it is possible to embed carriage returns in our text and have the echocommand's argument span multiple lines. While this is certainly an improvement, it does have a limitation. Since many types of markup used in html incorporate quotation marks themselves, it makes using a quoted string a little awkward. A quoted string can be used but each embedded quotation mark will need to be escaped with a backslash character. In order to avoid the additional typing, we need to look for a better way to produce our text. Fortunately, the shell provides one. It's called a here script. # sysinfo_page - A script to produce an HTML file http://linuxcommand.org/lc3_wss0030.php 4/8

# sysinfo_page - A script to produce an HTML file cat << _EOF_ <html> The title of your page Your page content goes here. </html> _EOF_ A here script (also sometimes called a here document) is an additional form of I/O redirection. It provides a way to include content that will be given to the standard input of a command. In the case of the script above, the standard input of the cat command was given a stream of text from our script. A here script is constructed like this: command << token content to be used as command's standard input http://linuxcommand.org/lc3_wss0030.php 5/8

content to be used as command's standard input token token can be any string of characters. I use "_EOF_" (EOF is short for "End Of File") because it is traditional, but you can use anything, as long as it does not conflict with a bash reserved word. The token that ends the here script must exactly match the one that starts it, or else the remainder of your script will be interpreted as more standard input to the command. There is one additional trick that can be used with a here script. Often you will want to indent the content portion of the here script to improve the readability of your script. You can do this if you change the script as follows: # sysinfo_page - A script to produce an HTML file cat <<- _EOF_ <html> The title of your page http://linuxcommand.org/lc3_wss0030.php 6/8

Your page content goes here. </html> _EOF_ Changing the the "<<" to "<<-" causes bash to ignore the leading tabs (but not spaces) in the here script. The output from the cat command will not contain any of the leading tab characters. O.k., let's make our page. We will edit our page to get it to say something: # sysinfo_page - A script to produce an HTML file cat <<- _EOF_ <html> My System Information http://linuxcommand.org/lc3_wss0030.php 7/8

<h1>my System Information</h1> </html> _EOF_ In our next lesson, we will make our script produce real information about the system. 2000-2015, William E. Shotts, Jr. Verbatim copying and distribution of this entire article is permitted in any medium, provided this copyright notice is preserved. Linux is a registered trademark of Linus Torvalds. http://linuxcommand.org/lc3_wss0030.php 8/8