Lab 4: Shell Scripting

Similar documents
Lab 4: Bash Scripting

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

CSE 15L Winter Midterm :) Review

Lab #2 Physics 91SI Spring 2013

Agenda. - Final Project Info. - All things Git. - Make sure to come to lab for Python next week

When talking about how to launch commands and other things that is to be typed into the terminal, the following syntax is used:

Lab 08. Command Line and Git

Software Development I

Git Setup Help using GitKraken (CSE 154)

Lab 1 Introduction to UNIX and C

DAVE LIDDAMENT INTRODUCTION TO BASH

1. Git. Robert Snapp

Linux File System and Basic Commands

CSC209. Software Tools and Systems Programming.

CSCE UVM Hands-on Session-1 Pre-Work

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

Chapter 4. Unix Tutorial. Unix Shell

Shell Scripting. Jeremy Sanders. October 2011

28-Nov CSCI 2132 Software Development Lecture 33: Shell Scripting. 26 Shell Scripting. Faculty of Computer Science, Dalhousie University

CS 3410 Intro to Unix, shell commands, etc... (slides from Hussam Abu-Libdeh and David Slater)

C Shell Tutorial. Section 1

CS 460 Linux Tutorial

Introduction to Supercomputing

Linux Operating System Environment Computadors Grau en Ciència i Enginyeria de Dades Q2

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

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

CpSc 111 Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input

CSE 374: Programming Concepts and Tools. Eric Mullen Spring 2017 Lecture 4: More Shell Scripts

Git. Charles J. Geyer School of Statistics University of Minnesota. Stat 8054 Lecture Notes

CSC209. Software Tools and Systems Programming.

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

What is Bash Shell Scripting?

Review of Fundamentals

Scripting. More Shell Scripts Loops. Adapted from Practical Unix and Programming Hunter College

Problem Set 1: Unix Commands 1

Network Administration/System Administration (NTU CSIE, Spring 2018) Homework #1. Homework #1

CSCI Operating Systems, Winter 2019 Lab 1 : Introduction to the BLITZ Tools, git, kpl, makefile, etc. Due Date: 21 January 2019

Git. all meaningful operations can be expressed in terms of the rebase command. -Linus Torvalds, 2015

Shell scripting and system variables. HORT Lecture 5 Instructor: Kranthi Varala

Computer Science 330 Operating Systems Siena College Spring Lab 5: Unix Systems Programming Due: 4:00 PM, Wednesday, February 29, 2012

Introduction: What is Unix?

Carnegie Mellon. Linux Boot Camp. Jack, Matthew, Nishad, Stanley 6 Sep 2016

Exercise 1: Basic Tools

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

15-122: Principles of Imperative Computation

Advanced Linux Commands & Shell Scripting

CS356: Discussion #1 Development Environment. Marco Paolieri

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Online Remote Repositories

CpSc 1011 Lab 5 Conditional Statements, Loops, ASCII code, and Redirecting Input Characters and Hurricanes

Essentials for Scientific Computing: Bash Shell Scripting Day 3

CMSC 201 Spring 2018 Lab 01 Hello World

27-Sep CSCI 2132 Software Development Lab 4: Exploring bash and C Compilation. Faculty of Computer Science, Dalhousie University

Dalhousie University CSCI 2132 Software Development Winter 2018 Lab 8, March 22

Git and Command Line. Introduction. Part A: git

Computer Science 62 Lab 8

Lab 1 Introduction to UNIX and C

Lecture 01 - Working with Linux Servers and Git

COMS 6100 Class Notes 3

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

CST8207: GNU/Linux Operating Systems I Lab Ten Boot Process and GRUB. Boot Process and GRUB

bash Scripting Introduction COMP2101 Winter 2019

Shell Project Part 1 (140 points)

The Online Unix Manual

Section 1: Tools. Contents CS162. January 19, Make More details about Make Git Commands to know... 3

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

Introduction To. Barry Grant

9.2 Linux Essentials Exam Objectives

Intro to Linux. this will open up a new terminal window for you is super convenient on the computers in the lab

Each student will work independently on several tasks. This assignment will demonstrate the student's ability to:

Assignment 1: Port & Starboard

Useful Unix Commands Cheat Sheet

Bourne Shell Reference

ITST Searching, Extracting & Archiving Data

BASH Programming Introduction

How to version control like a pro: a roadmap to your reproducible & collaborative research

CSCI 2132: Software Development

Lecture 2: Data in Linguistics, Git/GitHub, Jupyter Notebook. LING 1340/2340: Data Science for Linguists Na-Rae Han

Table Of Contents. 1. Zoo Information a. Logging in b. Transferring files 2. Unix Basics 3. Homework Commands

Command Line Interface The basics

CSE 374 Programming Concepts & Tools. Brandon Myers Winter 2015 Lecture 4 Shell Variables, More Shell Scripts (Thanks to Hal Perkins)

CSCI 2132 Software Development. Lecture 5: File Permissions

CSE 374 Midterm Exam 11/2/15 Sample Solution. Question 1. (10 points) Suppose the following files and subdirectories exist in a directory:

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

Linux environment. Graphical interface X-window + window manager. Text interface terminal + shell

The Unix Shell & Shell Scripts

BEGINNER PHP Table of Contents

Application documentation Documentation

Bash command shell language interpreter

Introduction to UNIX Command Line

Introduction to the UNIX command line

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

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

CMPS 12A Introduction to Programming Lab Assignment 7

Version Control with GIT

Introduction. File System. Note. Achtung!

CSE 390a Lecture 3. bash shell continued: processes; multi-user systems; remote login; editors

More Scripting Techniques Scripting Process Example Script

CS246-Assign01 V1.1: Winter 2013

Transcription:

Lab 4: Shell Scripting Nathan Jarus June 12, 2017 Introduction This lab will give you some experience writing shell scripts. You will need to sign in to https://git.mst.edu and git clone the repository for this lab. Your repository will be named something along the lines of 2017SS-A-lab04-nmjxv3. Make sure to clone with the HTTPS URL (unless youve set up SSH keys). I strongly advise you to experiment and to test your code as you go along! Bash is a little weird, so checking to make sure it s doing what you think it is is important. Problem 1: Menus and Files Make a shell script named menu.sh that loops through all the files in the current directory and for each file, prints out a menu: v) View file e) Edit file c) Compile file Then the script gets the user s choice and does it. Consult the following list to see what it is: View file: Open the file with less Edit file: Open the file in a text editor (your choice which one) Compile file: Compile the file with g++ Quit: Bail out of the loop with break or exit Anything else: Print an error message and go to the next file For example, if the current directory contains file.cpp, file.h, goog.sh, and menu.sh, your output might look something like this: 1

$ bash menu.sh v) View file.cpp e) Edit file.cpp c) Compile file.cpp e v) View file.h e) Edit file.h c) Compile file.h v v) View goog.sh e) Edit goog.sh c) Compile goog.sh f INVALID RESPONSE Skipping this file! v) View menu.sh e) Edit menu.sh c) Compile menu.sh q Hints and requirements: Your script needs at least one function You should probably use a case statement! for file in *.txt loops over all.txt files in the current directory. Problem 2: Your Own (Terrible) Search Engine Write a bash script named goog.sh that counts the occurrence of a string in the source of a web page. Here are some examples: # Look for "Jake" on the specified web page $ bash goog.sh Jake http://dsl.mwisely.xyz/labs/3/assignment/ Jake: 11 # Look for "the" on the specified web page 2

$ bash goog.sh the http://dsl.mwisely.xyz/labs/3/assignment/ the: 43 # Look for "The" on the specified web page $ bash goog.sh The http://dsl.mwisely.xyz/labs/3/assignment/ The: 2 # Look for "cake" on the specified web page $ bash goog.sh cake http://dsl.mwisely.xyz/labs/3/assignment/ cake: 0 # Give it the wrong number of arguments to see the usage $ bash goog.sh Usage goog.sh WORD WEBSITE Behavior: Your script always takes exactly 2 arguments: The string to search for The URL of the website were looking at If the user misuses your script, it should show them the usage. The program must print the number of times the word appears in the web pages source (case sensitive!) Hints: You ll want an if statement to check the number of arguments Use exit NUM to exit the shell script and return NUM to the shell. You should use pipes to redirect output The following commands may be useful: wget downloads webpages. The -O flag can be used to direct downloaded content to standard out. The --quiet flag suppresses the download progress. grep searches for occurrences of a string pattern The -o flag prints each match on its own line. wc counts lines, words, and characters The -l flag just prints the number of lines. 3

Problem 3: Big Trouble in Little Whitespace For this problem, follow the directions and write your answers in a file named answers.txt. 1. Use compiley.sh to compile program.cpp into an executable named hello. (a) What is the command you ran in order to compile program.cpp to hello using compiley.sh? (b) Briefly describe how the script works in plain English. (You dont need to explain the echos.) 2. Rename your program to my program.cpp by running mv program.cpp "my program.cpp". You can run ls -l to make sure your file name has that space in it. (a) Can you still compile your program with compiley.sh? # Don t forget to escape the space when you run the script! $ bash compiley.sh my\ program.cpp hello # Or, you could use quotes $ bash compiley.sh "my program.cpp" hello (b) Based on the output and g++ error messages, what is the problem? 3. Change the last line of compiley.sh to compile file $@ and try compiling your program again. (a) Does compiley.sh work now? (b) Whats the problem this time? 4. Change the last line of compiley.sh to compile file "$@" and try compiling your program again. (a) Does compiley.sh work now? (b) Why did the double quotes ( ) fix the problem? Epilogue As with lab 2, your git repo on git.mst.edu is your submission. Don t forget to git add all the files you want to submit, git commit them, and git push your changes so the grader can download them! Your repo should contain the following files: README.md 4

compiley.sh program.cpp menu.sh goog.sh answers.txt 5