CSE 15L Winter Midterm :) Review

Similar documents
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

Introduction to the UNIX command line

Introduction: What is Unix?

Shell. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong

CSE 390a Lecture 2. Exploring Shell Commands, Streams, and Redirection

Linux shell programming for Raspberry Pi Users - 2

Introduction to Supercomputing

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

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

Useful Unix Commands Cheat Sheet

DAVE LIDDAMENT INTRODUCTION TO BASH

CSE 390a Lecture 2. Exploring Shell Commands, Streams, Redirection, and Processes

Exercise 1: Basic Tools

Lab 4: Shell Scripting

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

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

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

CS 261 Recitation 1 Compiling C on UNIX

UNIX System Programming Lecture 3: BASH Programming

Basic Linux (Bash) Commands

Unix Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : December, More documents are freely available at PythonDSP

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

CSCI 2132: Software Development. Norbert Zeh. Faculty of Computer Science Dalhousie University. Shell Scripting. Winter 2019

INTRODUCTION TO SHELL SCRIPTING ITPART 2

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

BASH Programming Introduction

The Unix Shell & Shell Scripts

Essentials for Scientific Computing: Bash Shell Scripting Day 3

Common File System Commands

Shell Scripting. With Applications to HPC. Edmund Sumbar Copyright 2007 University of Alberta. All rights reserved

CSCI 2132 Software Development. Lecture 5: File Permissions

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

Shells & Shell Programming (Part B)

Lab 4: Bash Scripting

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

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

PROGRAMMAZIONE I A.A. 2015/2016

5/20/2007. Touring Essential Programs

Introduction to the shell Part II

CSC UNIX System, Spring 2015

Bash Shell Programming Helps

Review of Fundamentals

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

Recitation #1 Boot Camp. August 30th, 2016

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

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

Shells and Shell Programming

CSC209 Review. Yeah! We made it!

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

Assignment clarifications

Using the Unix system. UNIX Introduction

Processes and Shells

Bourne Shell Reference

Scripting Languages Course 1. Diana Trandabăț

A Brief Introduction to the Linux Shell for Data Science

Basics. I think that the later is better.

Linux Systems Administration Shell Scripting Basics. Mike Jager Network Startup Resource Center

CSE 303 Lecture 2. Introduction to bash shell. read Linux Pocket Guide pp , 58-59, 60, 65-70, 71-72, 77-80

COMP2100/2500 Lecture 16: Shell Programming I

sottotitolo A.A. 2016/17 Federico Reghenzani, Alessandro Barenghi

Linux and Git Boot Camp

Recitation #1 Unix Boot Camp. August 29th, 2017

Chapter 4. Unix Tutorial. Unix Shell

CSC209. Software Tools and Systems Programming.

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

CENG 334 Computer Networks. Laboratory I Linux Tutorial

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

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

Unix Tools / Command Line

CS356: Discussion #1 Development Environment. Marco Paolieri

Introduction to Linux Basics Part II. Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala

CS 307: UNIX PROGRAMMING ENVIRONMENT FIND COMMAND

Shells. A shell is a command line interpreter that is the interface between the user and the OS. The shell:

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

Linux Refresher (1) 310/ Fourth Workshop on Distributed Laboratory Instrumentation Systems (30 October - 24 November 2006)

Introduction To. Barry Grant

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

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

Intro to Linux & Command Line

Shell script/program. Basic shell scripting. Script execution. Resources. Simple example script. Quoting

Basic UNIX Commands BASIC UNIX COMMANDS. 1. cat command. This command is used to create a file in unix. Syntax: $ cat filename

Project 1. Fast correction

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

BASH and command line utilities Variables Conditional Commands Loop Commands BASH scripts

Welcome to the Bash Workshop!

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

Chapter 1 - Introduction. September 8, 2016

Conditional Control Structures. Dr.T.Logeswari

CMPT 300. Operating Systems. Brief Intro to UNIX and C

UNIX Shell Programming

Computer Systems and Architecture

More Linux Shell Scripts

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

Basic UNIX Commands BASIC UNIX COMMANDS. 1. cat command. This command is used to create a file in unix. Syntax: $ cat filename

CSE 303 Lecture 4. users/groups; permissions; intro to shell scripting. read Linux Pocket Guide pp , 25-27, 61-65, , 176

Lecture 10: Potpourri: Enum / struct / union Advanced Unix #include function pointers

Introduction to UNIX Command Line

Today. Review. Unix as an OS case study Intro to Shell Scripting. What is an Operating System? What are its goals? How do we evaluate it?

CS246 Spring14 Programming Paradigm Files, Pipes and Redirection

Transcription:

CSE 15L Winter 2015 Midterm :) Review

Makefiles

Makefiles - The Overview Questions you should be able to answer What is the point of a Makefile Why don t we just compile it again? Why don t we just use a shell script? What is the format of a Makefile? How do we define variables in Makefiles? How do we call make in subdirectories?

Makefiles - The Format Dependencies can be files or targets Basic Structure: target: dependencies action Note: Each action must be tab-indented

Makfile - The Example

Suffix Directives

Makefile Macros

Calling another Makefile

Unix Shell Scripting

Piping/Filtering What is a pipe used for? A pipe is used to redirect the output of one command to the input of another. What does a pipe look like? A pipe is a vertical bar Note: This is the same symbol used in or Show me an Example. ls -l grep Apr ls wc man ksh grep history wc -l

Shell Scripting Lines starting with # are comments, but the first line #! is not a comment; it indicates the location of the shell that will be run Quote characters double quote: if a string is enclosed in the references to variables will be replaced with their values single quote: taken literally ` back quote: treated as command echo Date is: `date` chmod is used to change the permissions so we can run our script Wildcards: http://ieng6.ucsd.edu/~cs15w/lab1_kjasdf/page4.html

Declarations Are these two different? 1) y=5 2) y = 5

Loops Instead of using braces {} to control logic flow and statement blocks, shell uses terminating words: if, then/ fi case / esac for, do, done for i in {1..10} do while, do, done if [ $[i % 2] = 1 ]; then echo $i is odd else echo $i is even fi done

Shell Scripting Which one of these is the correct way to start a bash script? A.!# /bin/bash B. # bin/bash C.! /bin/bash D. #! /bin/bash

Shell Scripting Which one of these is the correct way to start a bash script? A.!# /bin/bash B. # bin/bash C.! /bin/bash D. #! /bin/bash

Shell Scripting (declarations) Array declarations: y=(hello hi hey) To access declared variables, use $ and braces echo ${y[0]} Hello is printed Declarations must not include spaces around equals sign

Examples for (( c=1; c<=5; c++ )) do echo "Welcome $c times" done c=0 while [ $c -lt 10 ] do echo The counter is $c let c=c+1 done echo Enter a fruit: read fruit case $fruit in apple) echo Apple ;; banana) echo Banana ;; *) echo Something else ;; esac

Examples (more) ls while read line do echo Hello ${line}! done filename=$1 cat $filename while read line do echo Hello ${line}! done filename=$1 while read line do echo Hello ${line}! done < $filename

Standard Streams http://upload.wikimedia.org/wikipedia/commons/7/70/stdstreams-notitle.svg

Redirecting Streams http://tldp.org/howto/bash-prog-intro-howto-3.html 1: stdout 2 file ls -l > ls-l.txt 2: stderr 2 file man grep grep -n man 2> errors.txt 3: stdout 2 stderr man grep grep -n man 1>&2 4: stderr 2 stdout man grep grep -n man 2>&1 5: stderr and stdout 2 file man grep grep -n man &> /dev/null

Redirection Commands Command pgm > file pgm < file pgm >> file n > file n >> file Description Output of pgm is redirected to file Program pgm reads its input from file. Output of pgm is appended to file. Output from stream with descriptor n redirected to file. Output from stream with descriptor n appended to file. n >& m Merge output from stream n with stream m. n <& m Merge input from stream n with stream m. Takes output from one program, or process, and sends it to another. http://www.tutorialspoint.com/unix/unix-io-redirections.htm

What you should know Know the difference between echo and cat Variable declarations How to call variables How strings, ``, work in bash How to use simple constructs like if statements, for loops, etc Commands like cd, rm, mv, cp, etc If you don t know what a command does type man <command> Site to test: http://www.tutorialspoint.com/execute_bash_online.php

Git

What is Git? Git is a distributed version control system.

Local git project layout

Git file lifecycle

Git commands git init Initialize a new git repo git add <file> Add/Stage a new file to your repo git commit -m message Commit staged changes to your repo

Git commands git status Show the status of files in the directory git log Log of all the commits made to the repo git diff File differences for unstaged, modified files

Git commands git pull pull changes from a remote server git push push changes to a remote server git remote add adding a remote server

Git commands git branch <branchname> Create a new branch git checkout <branchname> Checkout new branch git merge <branchname> Merge branch with current branch

TDD & JUnit

Test-Driven Development

Test-Driven Development JUnit is a tool used for TDD In TDD, tests are written before software. You must understand requirements first! Regression testing Everytime you change code, run original tests! Make sure old features work after adding new ones.

Test-Driven Development What is a unit? A single method. Why use unit testing? Find problems early. Documentation, shows how to use method. Why not to use Doesn t test full software. Takes a long time to write all those tests.

JUnit JUnit is a widely used framework for unit testing in Java. Makes testing standardized and easy (relatively easier) to implement. Testing whole suites at once.

JUnit Terminology Test fixture - sets up the data needed to run tests. Unit Test - A piece of code written by developer that executes a particular part of the code being tested. Test case - Tests the response of a single method to a particular set of inputs.

JUnit Terminology Test suite - Collection of test cases. Test runner - Software that runs your tests. Integration test - how well classes work together. Not good in JUnit. http://www.vogella.com/tutorials/junit/article.html <- Useful source! http://ieng6.ucsd.edu/~cs15f/lab3_fdw/index.html <- More info here!

JUnit Tests pass when they return without failing or throwing exceptions. Failure happens when JUnit assertion fails. Want to pass all the tests!

Other Frameworks JUnit - JAVA cppunit - C++ PHPUnit - PHP NUnit -.NET All have: Test Runner, Test Cases, Test fixtures, Test suites, Test Execution

GDB & Valgrind

GDB Cheatsheet When compiling, use -g, so debugging information can be in your executable file. e.g. $gcc -g -o myprogram myprogram.c To start gdb: $gdb./myprogram (e.g. $gdb./driver ) In the GDB console: run (to run your program) break x (where x is the name of your function in your program, line number) next (executes one more line, without stepping into the function if called) continue (when the program has stopped, it resumes execution) step (executes one more line, stepping into a function if called) print x (where x is an expression that can involve constants and variables) quit (to quit out of gdb)

Valgrind Cheatsheet Compile using debug information option (-g) to get more info in valgrind. $gcc -g -o myprogram myprogram.c To run valgrind: $valgrind./myprogram (e.g. $valgrind./driver)

Valgrind output ==15640== ==15640== HEAP SUMMARY: ==15640== in use at exit: 10 bytes in 5 blocks ==15640== total heap usage: 5 allocs, 0 frees, 10 bytes allocated ==15640== ==15640== LEAK SUMMARY: ==15640== definitely lost: 10 bytes in 5 blocks ==15640== indirectly lost: 0 bytes in 0 blocks ==15640== possibly lost: 0 bytes in 0 blocks ==15640== still reachable: 0 bytes in 0 blocks ==15640== suppressed: 0 bytes in 0 blocks ==15640== Rerun with --leak-check=full to see details of leaked memory

Valgrind output (no leaks) ==18957== ==18957== HEAP SUMMARY: ==18957== in use at exit: 0 bytes in 0 blocks ==18957== total heap usage: 5 allocs, 5 frees, 10 bytes allocated ==18957== ==18957== All heap blocks were freed -- no leaks are possible ==18957== ==18957== For counts of detected and suppressed errors, rerun with: -v ==18957== ERROR SUMMARY: 28 errors from 15 contexts (suppressed: 12 from 8

Thank you!