LING 408/508: Computational Techniques for Linguists

Slides:



Advertisements
Similar presentations
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
Advertisements

Linux Shell Script. Shell script The first line is used to specify shell program #!/bin/sh Variables variable=“text” variable=0 variable=`program arguments`
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Unix Basics. Systems Programming: Unix Basics 2 Unix Basics  Unix directories  Important Unix file commands  File and Directory Access Rights through.
Using Macs and Unix Nancy Griffeth January 6, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis of Complex.
Introduction to Linux Workshop February Introduction Rob Lane & The HPC Support Team Research Computing Services CUIT.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
Chapter 5 Bourne Shells Scripts By C. Shing ITEC Dept Radford University.
Unix Basics Chapter 4.
LING 408/508: Programming for Linguists Lecture 3 August 31 st.
Unix Tutorial for FreeSurfer Users. Helpful To Know FreeSurfer Tutorial Wiki:
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
Unix Tutorial for FreeSurfer Users. Helpful To Know FreeSurfer Tutorial Wiki:
Linux Operations and Administration
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 11: Shell.
Scripting Languages Course 2 Diana Trandab ă ț Master in Computational Linguistics - 1 st year
Shell Programming. Introducing UNIX Shells  Shell is also a programming language and provides various features like variables, branching, looping and.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
LING 408/508: Programming for Linguists Lecture 4 September 2 nd.
Shell Programming. Creating Shell Scripts: Some Basic Principles A script name is arbitrary. Choose names that make it easy to quickly identify file function.
Shells. Variables MESSAGE="HELLO WORLD" echo $MESSAGE MESSAGE="HELLO WORLD $LOGNAME" echo $MESSAGE MESSAGE="HELLO WORLD $USER" echo $MESSAGE.
Introduction to Programming Using C An Introduction to Operating Systems.
LING 408/508: Programming for Linguists Lecture 8 September 23 rd.
CS252: Systems Programming Ninghui Li Slides by Prof. Gustavo Rodriguez-Rivera Topic 7: Unix Tools and Shell Scripts.
Introduction to Scripting Workshop October
Linux Commands C151 Multi-User Operating Systems.
Agenda Positional Parameters / Continued... Command Substitution Bourne Shell / Bash Shell / Korn Shell Mathematical Expressions Bourne Shell / Bash Shell.
LING 408/508: Programming for Linguists Lecture 5 September 9 th.
Sed. Class Issues vSphere Issues – root only until lab 3.
Learning basic Unix command It 325 operating system.
#!/bin/sh 2002/07/26 Jaeho Shin. Interface between user and the operating system sh, bash, csh, tcsh, ksh, … What is a “Shell”? OSuser Shell.
Introduction to Linux Workshop February 15, 2016.
File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here cal.txt on screen (or standard out).
 Prepared by: Eng. Maryam Adel Abdel-Hady
 Prepared by: Eng. Maryam Adel Abdel-Hady
Linux Administration Working with the BASH Shell.
Introduction to Scripting Workshop February 23, 2016.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Bash Scripting CIRC Summer School 2016 Baowei Liu CIRC Summer School 2016 Baowei Liu.
COMP075 OS2 Bash Scripting. Scripting? BASH provides access to OS functions, like any OS shell Also like any OS shell, BASH includes the ability to write.
By Jonathan Rinfret UNIX/LINUX By Jonathan Rinfret
UNIX To do work for the class, you will be using the Unix operating system. Once connected to the system, you will be presented with a login screen. Once.
CIRC Winter Boot Camp 2017 Baowei Liu
Chapter 11 Command-Line Master Class
Prepared by: Eng. Maryam Adel Abdel-Hady
Bash Introduction (adapted from chapters 1 and 2 of bash Cookbook by Albing, Vossing, & Newham) CPTE 440 John Beckett.
Andy Wang Object Oriented Programming in C++ COP 3330
Agenda Bash Shell Scripting – Part II Logic statements Loop statements
C151 Multi-User Operating Systems
The Linux Operating System
Shell Script Assignment 1.
CSE 303 Concepts and Tools for Software Development
Tutorial of Unix Command & shell scriptS 5027
Basic UNIX OLC Training.
Introduction to UNIX.
Tutorial of Unix Command & shell scriptS 5027
Using Linux Commands Lab 3.
LING 408/508: Computational Techniques for Linguists
LING 408/508: Computational Techniques for Linguists
Tutorial of Unix Command & shell scriptS 5027
Andy Wang Object Oriented Programming in C++ COP 3330
Linux Shell Script Programming
CSE 303 Concepts and Tools for Software Development
Lab 2: Terminal Basics.
Chapter 5 Bourne Shells Scripts
Introduction to Bash Programming, part 3
Presentation transcript:

LING 408/508: Computational Techniques for Linguists Lecture 5

Host OS: MacOS or Windows 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 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) The shell has a programming language dpkg –l (list)

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

Shell -rw-r--r-- 1 sandiway staff 0 Sep 4 09:26 tmp Directory shortcuts: your home directory: ~ current directory: . parent directory: .. Examples: cd .. (go to parent directory) mkdir ~/tmp (create a new directory called tmp in your home directory) touch tmp (create a new file tmp in the current directory if tmp doesn’t already exist, or update the timestamp) ls -l tmp (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 cat file1 (print contents of file1) cat file1 > file2 (‘>’ = redirect output to file2) cat file2 | more (‘|’ = pipe output to command more) more file1 – easier (stops at end of screen, hit space to show more) less file1 – easier (allows page by page display) cat > file1 (create file1 with input from terminal until Control-D EOF) cat (input from terminal goes to terminal) cat >> file1 (append input from terminal to file file1) cat file1 > file2 (file copy) cp file1 file2 – easier (cp = copy) cat file1 file2 file3 (prints all 3 files) cat file1 file2 file3 > file4 (prints all 3 files to file4) cat file1 file2 file3 | sort > file4 (3 files sorted alphabetically to file4) cat – file5 > file6 (‘-’ = input from terminal) 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)) (spaces not significant) echo $((1+3)) ((i=i+1)) (also ok let i=$i+1)

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

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 echo "1st parameter: $1" fi 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 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 -rwxr--r-- 1 sandiway staff 98 Sep 4 09:14 test.sh Number of parameters: 0 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)

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) Explanation: echo "…" | means send "..." to next command bc –q means quiet mode Explanation: `…` is command substitution bc -l, use the mathlib In bc, a(1) computes tan-1(1), which is π/4 pi=`echo "scale=50; 4*a(1)" | bc –l` (-l math library) echo $pi 3.14159265358979323846264338327950288419716939937508

First Non-trivial Program Some possibilities: