Assignment 1: Communicating with Programs

Similar documents
CSC209. Software Tools and Systems Programming.

The print queue was too long. The print queue is always too long shortly before assignments are due. Print your documentation

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

Essential Unix and Linux! Perl for Bioinformatics, ! F. Pineda

5/20/2007. Touring Essential Programs

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

Unix. Examples: OS X and Ubuntu

First steps on Linux and programming

CSC209. Software Tools and Systems Programming.

: the User (owner) for this file (your cruzid, when you do it) Position: directory flag. read Group.

Bash Shell Programming Helps

UNIX Kernel. UNIX History

Essentials for Scientific Computing: Bash Shell Scripting Day 3

Chapter 1 - Introduction. September 8, 2016

CS 307: UNIX PROGRAMMING ENVIRONMENT FIND COMMAND

Introduction Variables Helper commands Control Flow Constructs Basic Plumbing. Bash Scripting. Alessandro Barenghi

/ Cloud Computing. Recitation 5 September 27 th, 2016

find starting-directory -name filename -user username

CSC 2500: Unix Lab Fall 2016

Principles of Bioinformatics. BIO540/STA569/CSI660 Fall 2010

I/O and Shell Scripting

The Unix Shell & Shell Scripts

Basic Unix. Set-up. Finding Terminal on the imac. Method 1. Biochemistry laboratories Jean-Yves Sgro

TECH 4272 Operating Systems

Basic UNIX commands. HORT Lab 2 Instructor: Kranthi Varala

Answers to AWK problems. Shell-Programming. Future: Using loops to automate tasks. Download and Install: Python (Windows only.) R

Creating a Shell or Command Interperter Program CSCI411 Lab

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1

The Linux Command Line: A Complete Introduction, 1 st ed., by William E. Shotts, Jr., No Starch Press, 2012.

Lec 1 add-on: Linux Intro

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

Introduction: What is Unix?

Part I. UNIX Workshop Series: Quick-Start

Lecture 8. Introduction to Shell Programming. COP 3353 Introduction to UNIX

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

UNIX System Programming Lecture 3: BASH Programming

Introduction in Unix. Linus Torvalds Ken Thompson & Dennis Ritchie

Introduction To. Barry Grant

The UNIX Operating System. HORT Lecture 2 Instructor: Kranthi Varala

introduction week 1 Ritsumeikan University College of Information Science and Engineering Ian Piumarta 1 / 20 imperative programming about the course

Shell Scripting. Jeremy Sanders. October 2011

PROGRAMMING PROJECT ONE DEVELOPING A SHELL

Table of Contents EVALUATION COPY

Vi & Shell Scripting

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

PROGRAMMAZIONE I A.A. 2015/2016

Problem Set 1: Unix Commands 1

CS Programming Languages Fall Homework #2

Lecture 8: Structs & File I/O

Mills HPC Tutorial Series. Linux Basics I

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Summer 2016 Programming Assignment 1 Introduction The purpose of this

AOS 452 Lab 9 Handout Automated Plot Generation

CS 307: UNIX PROGRAMMING ENVIRONMENT KATAS FOR EXAM 2

Lecture 7: file I/O, more Unix

An Introduction to Unix Power Tools

Principles of computer programming. Profesor : doc. dr Marko Tanasković Assistent : doc. dr Marko Tanasković

Unix Shell. Advanced Shell Tricks

Processes. Shell Commands. a Command Line Interface accepts typed (textual) inputs and provides textual outputs. Synonyms:

A shell can be used in one of two ways:

COMP 412, Fall 2018 Lab 1: A Front End for ILOC

CISC 220 fall 2011, set 1: Linux basics

Introduction to Unix The Windows User perspective. Wes Frisby Kyle Horne Todd Johansen

9.2 Linux Essentials Exam Objectives

UNIX Essentials Featuring Solaris 10 Op System

CSE 390a Lecture 1. introduction to Linux/Unix environment

CMPS 12A Introduction to Programming Lab Assignment 7

CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Homework 4 (document version 1.1) Sockets and Server Programming using C

Ling 473 Project 4 Due 11:45pm on Thursday, August 31, 2017

A Brief Introduction to the Linux Shell for Data Science

Pod::Usage, pod2usage() - print a usage message from embedded pod documentation

Assignment Tutorial.

LING 408/508: Computational Techniques for Linguists. Lecture 5

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

Sperimentazioni I LINUX commands tutorial - Part II

Important Project Dates

CS 361S - Network Security and Privacy Spring Project #2

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

Processes and Shells

Lab #2 Physics 91SI Spring 2013

Bash command shell language interpreter

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

Mills HPC Tutorial Series. Linux Basics II

CENG 334 Computer Networks. Laboratory I Linux Tutorial

EECS2301. Lab 1 Winter 2016

Process Management! Goals of this Lecture!

Unix basics exercise MBV-INFX410

Assignment clarifications

Assignment 2, due September 17

Command-line interpreters

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

CS Fundamentals of Programming II Fall Very Basic UNIX

Scripting Languages Course 1. Diana Trandabăț

CSE 391 Lecture 1. introduction to Linux/Unix environment

Introduction to the shell Part II

Modules and Programs 1 / 14

CSCI2467: Systems Programming Concepts

EECS 470 Lab 5. Linux Shell Scripting. Friday, 1 st February, 2018

DAVE LIDDAMENT INTRODUCTION TO BASH

Environment Variables

Project 3: Base64 Content-Transfer-Encoding

Transcription:

Assignment 1: Communicating with Programs EC602 Design by Software Fall 2018 Contents 1 Introduction 2 1.1 Assignment Goals........................... 2 1.2 Group Size.............................. 2 1.3 Due Date............................... 2 1.4 Late policy.............................. 2 1.5 Submission Link........................... 3 1.6 Points................................. 3 2 Tutorials 3 3 Background 3 3.1 Input and Output.......................... 3 3.2 Command-line arguments...................... 4 3.3 Executable programs in Unix.................... 4 3.3.1 Executable permissions................... 4 3.3.2 Scripts As Executables.................... 5 4 The Assignment 6 4.1 Python fourargs.py (1 point)................... 6 4.2 C++ fourargs.cpp (1 point).................... 6 4.3 Shell fourargs.sh (1 point)..................... 7 4.4 Executable Python Script oldest (1 point)............ 7 4.5 Executable Bash Script recent (1 point).............. 7 4.6 Hints.................................. 8 5 Assignment checker 8 1

1 Introduction 1.1 Assignment Goals The first assignment goals are to ensure you have the development environments available to you you are able to use the assignment submission system you can write and run simple C++ and Python programs you can use the unix terminal 1.2 Group Size For this assignment, the maximum group size is 1. Everyone must complete the assignment. However, you may help each other as much as you wish for this assignment. 1.3 Due Date This assignment is now due 2017-09-13 at midnight. The grace period is 48 hours. 1.4 Late policy Late assignments will be accepted through a grace period of H hours. Usually, H will be the number of hours until the beginning of the lecture immediately following the due date (the normal H is 14.5). The grade will be scaled on a linear scale from 100% at the deadline to 50% at the end of the grade period. If the natural grade on the assignment is g, the number of hours late is h, and the grace period is H, then the grade is grade = (h > H)? 0 : g * (1- h/(2*h)); in C++ or grade = 0 if h>h else g * (1- h/(2*h)) in python. If the same assignment is submitted ontime and late, the grade for that component will be the maximum of the ontime submission grade and the scaled late submission grade. 2

1.5 Submission Link You can submit here: week 1 submit link The submission link will activate on Monday morning. 1.6 Points This assignment is worth 5 points. 2 Tutorials If you are a total beginner at python, unix, or C++, here are three good places to start: C++: tutorial at cplusplus.com Python: Official Python Tutorial Unix: Unix tutorial for beginners 3 Background In unix, the shell or terminal provides an environment in which the program can interact with the operating system and user. One of the ways it does this is to provide input and output facilities to the terminal. The other way is by passing programs configuration options on the command line. These are called command-line arguments. 3.1 Input and Output The input and output streams are standard input (stdin): the program can read whatever is typed at the terminal standard output (stdout): normal output from the program goes here. standard error (stderr): when errors occur during execution of a program, the program normally sends the error messages here. By default, both stdout and stderr will appear together on the terminal, but they can be redirected to illustrate the difference Here are some examples: Put the list of files into my_file_list.txt, a new text file to be created: 3

ls > my_file_list.txt Compile my_prog.cpp and put errors, if any, in my_errors.txt g++ my_prog.cpp 2> my_errors.txt 3.2 Command-line arguments Most unix programs reserve stdin and stdout for data. Configuration options are typically specified as arguments specified on the command line. Normally, ls lists all files in the current directory. With command line arguments, this behavior can be modified: Examples: List the files in the directory /media ls /media Compile fourargs.cpp and make an executable called fourargs g++ fourargs.cpp -o fourargs In this example, there are three arguments: argument 1 is the name of the program to compile argument 2 is a symbol that g++ recognizes which means the next argument is the name of the output argument 3 is the name of the executable file to create 3.3 Executable programs in Unix There are several different types of applications or programs in all operating systems. Here, we focus on how these work in Linux / Unix environments. The word executable is both a noun (thing) and an adjective (description). A true executable is a file containing machine code. It will be loaded into memory by the OS and the code will be executed. When C++ programs are compiled, the result is a true executable program. 3.3.1 Executable permissions The word executable as an adjective refers to a permission setting on a file, which indicates to the operating system that this file is intended to be run as an executable (the noun). The permissions for a file are viewed with ls like this: 4

ls -l There are nine (3x3) permission flags: three access modes (read, write, and execute) for three entities (user, group, other). and they can be changed using chmod like this: chmod 755 a.out or chmod o+x recent Type man ls or man chmod to see all the options for these programs. 3.3.2 Scripts As Executables A text file containing bash commands or python commands can also be executed, in one of two ways, explicitly or implicitly. 3.3.2.1 Explicit scripting In this method, the scripting program is directly called from the terminal, and the name of the script is provided to that program as a command line argument. Here are examples: bash my_commands.sh or python my_commands.py in which case the files my_commands.sh and my_commands.py do not have to have executable permisions (the programs bash and python have the permissions!) 3.3.2.2 Implicit scripting If you want your script to look more like a real program (which we call implicit scripting to distinguish it from the case above) here is how it is done: 1. Change the name of the program to my_commands since the Unix convention is that executables do not have extensions. 2. Change the permissions of the program using chmod usually to 755 3. Add the following line to the beginning of your program #!/usr/bin/env python This is called a shebang statement and it tells the OS to run the rest of the program through the interpreter executable that follows. The program env looks up the location of the program python and runs it. 5

Alternatively, you can also add #!/home/ece-student/anaconda3/bin/python but this is less portable. 4 The Assignment This assignment is comprised of five short programs, each worth one point. 4.1 Python fourargs.py (1 point) Write a python program fourargs.py that outputs the first four arguments to stdout and any additional arguments, if any, to stderr. Each argument should appear on a line by itself. So, for example, if the program is run like this: python fourargs.py one two 3 four five six then the output to stdout will be one two 3 four and the output to stderr will be five six 4.2 C++ fourargs.cpp (1 point) Write a C++ program fourargs.cpp that outputs the first four arguments to stdout and any additional arguments, if any, to stderr. Each argument should appear on a line by itself. So, for example, if the program is run like this: fourargs one two 3 four five six then the output to stdout will be one two 3 four 6

and the output to stderr will be five six 4.3 Shell fourargs.sh (1 point) Write a script fourargs.sh that compiles the C++ program to an executable called fourargs runs the python program with 6 arguments runs the python program with 3 arguments runs the C++ program with 6 arguments runs the C++ program with 3 arguments 4.4 Executable Python Script oldest (1 point) Write an executable python script oldest which outputs the oldest files in the current directory, starting with the file modified furthest in the past, and working towards the newer files. Your program should accept one command line argument which represents the number of files to list. Here is an example: > oldest 3 nine eight seven [Assume there are nine files, one being the most recent and nine being the oldest] 4.5 Executable Bash Script recent (1 point) Write an executable bash script recent which outputs the most recent files in the current directory, starting with the file most recently modified, and working towards the older files. Your program should accept one command line argument which represents the number of files to list. Here is an example: > recent 5 one two three four five [Assume there are nine files, one being the most recent and nine being the oldest] 7

Hint: although it is not necessary to use a shebang line for bash scripts that are run from the command line, it is still a good idea. The checker does not run the program in a shell, and so it requires a shebang line. 4.6 Hints For python, research the sys module. For C++, research the iostream module. Caution: both python and C++ include an extra argument as argument 0. This extra argument is the name of the program. These programs should not print out argument 0. 5 Assignment checker You can check your work prior to submission using the assignment checker, which is a python program. args_checker.py To use the checker, download it into the same directory that has your five fourargs.cpp, fourargs.py, fourargs.sh, oldest, and recent and then run python args_checker.py 8