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

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

Linux Shell Scripting. Linux System Administration COMP2018 Summer 2017

9.2 Linux Essentials Exam Objectives

OPERATING SYSTEMS LAB LAB # 6. I/O Redirection and Shell Programming. Shell Programming( I/O Redirection and if-else Statement)

Essentials for Scientific Computing: Bash Shell Scripting Day 3

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

DAVE LIDDAMENT INTRODUCTION TO BASH

Week 2 Lecture 3. Unix

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

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

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

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

COMP 4/6262: Programming UNIX

Useful Unix Commands Cheat Sheet

Basic Linux (Bash) Commands

CS Unix Tools & Scripting

Shell Programming (bash)

Introduction to Linux Workshop 1

Chapter 4. Unix Tutorial. Unix Shell

Introduction: What is Unix?

Lab Working with Linux Command Line

Linux Shell Script. J. K. Mandal

UNIX shell scripting

Hands-on Keyboard: Cyber Experiments for Strategists and Policy Makers

Shell Start-up and Configuration Files

Linux Essentials Objectives Topics:

CSC 2500: Unix Lab Fall 2016

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

INd_rasN SOME SHELL SCRIPTING PROGRAMS. 1. Write a shell script to check whether the name passed as first argument is the name of a file or directory.

Mills HPC Tutorial Series. Linux Basics I

A shell can be used in one of two ways:

bash Tests and Looping Administrative Shell Scripting COMP2101 Fall 2017

Lecture 4. Log into Linux Reminder: Homework 1 due today, 4:30pm Homework 2 out, due next Tuesday Project 1 out, due next Thursday Questions?

The Unix Shell & Shell Scripts

Introduction to Linux (Part I) BUPT/QMUL 2018/03/14

CISC 220 fall 2011, set 1: Linux basics

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

Introduction to Linux

Perl and R Scripting for Biologists

CS246 Spring14 Programming Paradigm Notes on Linux

Introduction to Linux

Shells & Shell Programming (Part B)

Shell script. Shell Scripts. A shell script contains a sequence of commands in a text file. Shell is an command language interpreter.

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

Overview LEARN. History of Linux Linux Architecture Linux File System Linux Access Linux Commands File Permission Editors Conclusion and Questions

Introduction in Unix. Linus Torvalds Ken Thompson & Dennis Ritchie

Exploring UNIX: Session 3

bash Tests and Looping Administrative Shell Scripting COMP2101 Fall 2017

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

Introduction to UNIX. SURF Research Boot Camp April Jeroen Engelberts Consultant Supercomputing

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

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

Exercise sheet 1 To be corrected in tutorials in the week from 23/10/2017 to 27/10/2017

Unix as a Platform Exercises. Course Code: OS-01-UNXPLAT

Introduction to Unix and Linux. Workshop 1: Directories and Files

LINUX Scripts de Bash Shell. Exercise 1 - Working with Files

Assignment clarifications

Shells and Shell Programming

Lecture 3. Unix. Question? b. The world s best restaurant. c. Being in the top three happiest countries in the world.

Introduction to Linux

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

Introduction of Linux. Huang Cheng-Chao Dept. of Comput. Sci. & Tech. East China Normal University

Log into Linux Reminders: Homework 1 due today; Homework 2 due on Thursday Questions?

CS 307: UNIX PROGRAMMING ENVIRONMENT KATAS FOR EXAM 1

UNIX System Programming Lecture 3: BASH Programming

Bash, In A NutShell RUSTY MYERS - SYSTEMS ADMINISTRATOR, PENN STATE CHRIS LAWSON - IT CONSULTANT/SUPPORT SPECIALIST, PENN STATE ALTOONA

INTRODUCTION TO UNIX

Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Mauro Ceccanti e Alberto Paoluzzi

Introduction to Linux Part 1. Anita Orendt and Wim Cardoen Center for High Performance Computing 24 May 2017

Unix Shell scripting. Dr Alun Moon 7th October Introduction. Notation. Spaces

More Raspian. An editor Configuration files Shell scripts Shell variables System admin

CENG 334 Computer Networks. Laboratory I Linux Tutorial

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1

Linux Command Line Interface. December 27, 2017

Chapter-3. Introduction to Unix: Fundamental Commands

Shells and Shell Programming

Exercise Sheet 2. (Classifications of Operating Systems)

Linux Bash Shell Scripting

Unix basics exercise MBV-INFX410

Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Esercitazione Introduzione al linguaggio di shell

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

PROGRAMMAZIONE I A.A. 2015/2016

Lecture 5. Essential skills for bioinformatics: Unix/Linux

Std: XI CHAPTER-3 LINUX

Bash scripting basics

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

Introduction to the shell Part II

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

Title:[ Variables Comparison Operators If Else Statements ]

Vi & Shell Scripting

commandname flags arguments

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT

Bioinformatics? Reads, assembly, annotation, comparative genomics and a bit of phylogeny.

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

Shell Programming Overview

CSE374 Winter 2016, Midterm Examination February 8, 2016 Please do not turn the page until the bell rings.

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

Introduction to remote command line Linux. Research Computing Team University of Birmingham

LING 408/508: Programming for Linguists. Lecture 8 September 23 rd

I/O and Shell Scripting

Transcription:

LING 408/508: Computational Techniques for Linguists Lecture 5

Last Time Installing Ubuntu 18.04 LTS on top of VirtualBox Your Homework 2: did everyone succeed? Ubuntu VirtualBox Host OS: MacOS or Windows

Windows 10 install

Windows 10 install

Ubuntu Text editor

Ubuntu Text editor (built in) nano is a decent one for (use inside Terminal) can install others via sudo apt-get install or sudo apt install

Ubuntu Notes: which command returns path to command if found perl is pre-installed. python3 is pre-installed.

Ubuntu Terminal: runs a shell: bash The shell has a programming language enter commands: some are built-in to the shell, others are executable files in specified directories ($PATH), still others will require apt-get install or apt install. command history is editable (up-arrow to retrieve ) pre-defined environment variables: env lots of packages are pre-loaded: wish, python, perl, etc. dpkg (package manager for Debian) man command-name (brings up manual page) dpkg l (list)

Shell simple commands: pwd ls (ls -a) cd mkdir which name man name echo $SHELL echo $PATH print working directory list current directory (-a option: show. (dot) files too) change directory create a new directory prints the directory where command name is located, or nothing if it can t be found in the PATH display manual page for command name prints the shell ($ prefixes a variable) shows the directories where the shell will look for commands

Shell Directory shortcuts: your home directory: ~ current directory:. parent directory:.. Examples: cd.. mkdir ~/tmp touch tmp ls -l tmp (go to parent directory) (create a new directory called tmp in your home directory) (create a new file tmp in the current directory if tmp doesn t already exist, or update the timestamp) (list attributes of file tmp in long format) -rw-r--r-- 1 sandiway staff 0 Sep 4 09:26 tmp permissions user group all r = read w = write x = execute owner group size (bytes) date time modified filename

cat command See http://www.linfo.org/cat.html 1. cat file1 (print contents of file1) 2. cat file1 > file2 ( > = redirect output to file2) 3. cat file2 more ( = pipe output to command more) 4. more file1 easier (stops at end of screen, hit space to show more) 5. less file1 easier (allows page by page display) 6. cat > file1 (create file1 with input from terminal until Control-D EOF) 7. cat (input from terminal goes to terminal) 8. cat >> file1 (append input from terminal to file file1) 9. cat file1 > file2 (file copy) 10. cp file1 file2 easier (cp = copy) 11. cat file1 file2 file3 (prints all 3 files) 12. cat file1 file2 file3 > file4 (prints all 3 files to file4) 13. cat file1 file2 file3 sort > file4 (3 files sorted alphabetically to file4) 14. cat file5 > file6 ( - = input from terminal) 15. cat file7 - > file8

Shell Arithmetic at the shell prompt: expr 1 + 3 (Need spaces cf. expr 1+3) expr 2 '*' 2 (cf. expr 2 * 2) echo `expr 1 + 3` i=2 (NO SPACES! cf. i = 2) expr $i + 1 let x=1+3 (cf. let x=1 + 3) echo $x let i=$i+1 (also ok let i=i+1) echo $i ((x = 1+ 3)) echo $x echo $((1+3)) ((i=i+1)) (spaces not significant) (also ok let i=$i+1)

Comparison operators Format: if [ $x OP $y ]; then (else/elif ) fi [. ] is known as test OP: -eq -ne -gt -ge -lt -le equals not equals greater than greater than or equals less than less than or equals Examples: echo $x $i 2 5 test $x -le $i echo $? status) 0 (exit test $x -le $i -a $i -lt $x echo $? 1

Input At a terminal: read p Name: name read p Enter X and Y: x y echo $x echo $y

Positional Parameters In a shell script: $1: first parameter $#: number of parameters Program: #!/bin/bash echo "Number of parameters: $#" if [ $# -eq 1 ]; then fi echo "1st parameter: $1" Output: sh test.sh Number of parameters: 0 sh test.sh 45 Number of parameters: 1 1st parameter: 45 sh test.sh 45 56 Number of parameters: 2

Running shell scripts Supply program filename as a parameter to sh/bash: sh is dash, not bash anymore sh test.sh bash test.sh source test.sh. test.sh (. = source) Run the program in the current directory: (./ needed if current directory is not in PATH)./test.sh -bash:./test.sh: Permission denied ls -l test.sh -rw-r--r-- 1 sandiway staff 98 Sep 4 09:14 test.sh chmod u+x test.sh ls -l test.sh -rwxr--r-- 1 sandiway staff 98 Sep 4 09:14 test.sh./test.sh Number of parameters: 0

First Non-trivial Program Let s write a simple shell-script BMI calculator it can solicit input from the terminal or take command line arguments try the metric one first

First Non-trivial Program First pass:

BMI calculator Did you notice bash can only do integers? can use bc (an arbitrary precision calculator) scale = # of decimal places echo "scale=2;2/3" bc q.66 but test comparisons (-gt etc.) would then be a pain in the butt can re-scale the formula: Example: weight in kg * 1,000,000 / (height in cm)**2 echo $((68* 1000000 / (165 * 165))) 2497 (24.97) pi=`echo "scale=50; 4*a(1)" bc l` (-l math library) echo $pi 3.14159265358979323846264338327950288419716939937508 Explanation: 1. echo " " means send "..." to next command 2. bc q means quiet mode Explanation: 1. ` ` is command substitution 2. bc -l, use the mathlib 3. In bc, a(1) computes tan -1 (1), which is π/4

First Non-trivial Program Some possibilities: