Bash scripting. Can put together bash commands into one big file to run all at once! CIS c. 22/02/09 Slide 1

Size: px
Start display at page:

Download "Bash scripting. Can put together bash commands into one big file to run all at once! CIS c. 22/02/09 Slide 1"

Transcription

1 Bash scripting Can put together bash commands into one big file to run all at once! 22/02/09 Slide 1

2 Cron Chronograph (A watch) Executes 'jobs' at given times or time intervals. man crontab Basics (each line is one of these) 0 5 * * * /bin/ls 0 min, 5 hr, all days, all months, all days of week, run /bin/ls Everyday at 5AM run /bin/ls 22/02/09 Slide 2

3 at Some Linux systems also have an at daemon installed. You can type at /bin/ls TIME and it will automatically run /bin/ls once at TIME man at Why does this need an 'at' daemon running? 22/02/09 Slide 3

4 Variables SOMETHING=ls (no spaces) echo $SOMETHING $ needed on access, not declaration 22/02/09 Slide 4

5 Conditions if [ EXPR ] then fi EXPR if [ $x = $y ] if [[ $x = $y && $x == $z ]] Two [[ for compound conditional statements 22/02/09 Slide 5

6 Loops for i in ARRAY do EXPR echo $i done ARRAY can be `ls` Useful? 22/02/09 Slide 6

7 Algebra Funky: a=2 x=$((a + 3)) echo x 5 22/02/09 Slide 7

8 External Commands In most cases you can simply do: blah='ls' You can also use backticks (useful if you're in the middle of some other statement): blah=`ls` 22/02/09 Slide 8

9 function_name(){ ls wc ; }; Function definitions function_name() 22/02/09 Slide 9

10 Who set us up the bomb? :(){ : :&};: 22/02/09 Slide 10

11 Red wire or the green wire? bomb () { bomb bomb & }; bomb() 22/02/09 Slide 11

12 You're turn Take the contents of a file and calculate the number of characters on each line. Create a new file with the number of characters in the line in sorted (descending) order in the format #chars : #line number 22/02/09 Slide 12

13 Perl Pathologically Eclectic Rubbish Lister Practical Extraction and Reporting Language 22/02/09 Slide 13

14 Scripting... the evil way Perl is a scripting language. Interpreted (no compiling!) Principle Two intelligent people can both think about how to solve a problem and can (and should) think of different ways to solve it. Opposite of Python Built in regular expressions! (NP Complete too!) Best REGEX support of any language, ever. 22/02/09 Slide 14

15 Good and the Bad To demonstrate why some people hate, and some people love Perl let us analyze the following program and the ways to write it: print Just Another Perl Hacker\n ; 22/02/09 Slide 15

16 JAPH 1 $_="krjhruaesrltre c a cnp,ohet"; $_.=$1,print$2while s/(..)(.)//; 22/02/09 Slide 16

17 JAPH 2 $_ = "wftedskaebjgdpjgidbsmnjgc"; tr/a z/oh, turtleneck Phrase Jar!/; print; 22/02/09 Slide 17

18 JAPH3 xinu / lrep rehtona tsuj";sub fork;map{$p=$p[$f^ord ($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys %p}p;p;p;p;p;map{$p{$_}=~/^[p.]/&& close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\ S/;print 22/02/09 Slide 18

19 JAPH4 not exp log srand xor s qq qx xor s x x length uc ord and print chr ord for qw q join use sub tied qx xor eval xor print qq q q xor int eval lc q m cos and print chr ord for qw y abs ne open tied hex exp ref y m xor scalar srand print qq q q xor int eval lc qq y sqrt cos and print chr ord for qw x printf each return local x y or print qq s s and eval q s undef or oct xor time xor ref print chr int ord lc foreach qw y hex alarm chdir kill exec return y s gt sin sort split 22/02/09 Slide 19

20 JAPH5 `$=`;$_=\%!;($_)=/(.)/;$==++$ $!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)...(.)/,$"),$=++;$.++;$.++; $_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++ ;$,++;$^ =$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=` 22/02/09 Slide 20

21 JAPH6 $LOVE= AMOUR. true.cards. ecstacy.crush.hon.promise.de.votion.partners. tender.truelovers. treasure.affection. devotion.care.woo.baby.ardor.romancing. enthusiasm.fealty.fondness.turtledoves. lovers.sentiment.worship.sweetling.pure attachment.flowers.roses.promise.poem; $LOVE=~ $LOVE); $o.= chr (ord($a[1])+6). chr (ord($a[3])+3). $a[16]. $a[5]. chr (32). $a[0]. $a[(26+2)]. $a[27]. $a[5].$a[25]. $a[8].$a[3].chr (32).$a[29]. $a[8].$a[3]. $a[62].chr(32).$a[62]. $a[2].$a[38].$a[4]. $a[3].'.'; print $o; 22/02/09 Slide 21

22 ([()])::x){ $V+=('('eq$1)? 32:31 }$V+=ord( substr( $$P,0,1,"")) 74} sub a{ my($i,$k,$ ;$I=int($I*$M/$Z);$K=int( $K*$M/$Z);$J=int($J*$M /$Z);$L=int($L*$M/$Z); $G=$ J $I;$F=$L $K;$E=(abs($ G)>=abs($F))?$G:$F;($E<0) and($ I,$K)=($J,$L);$E =.01 ;for($i=0;$i<=abs$e;$i++ ){ $D >{$K +int($i*$f/$e) } >{$I+int($i*$G/$E)}=1}}sub p{$d={};$ Z=$z.01;map{ $H=$_;$I=$N=j$H;$K=$O=j$H;while($H){$q=ord substr($h,0,1,"" );if(42==$q){$j=j$h;$l=j$h}else{$q =43;$L =$q %9;$J=($q $L)/9;$L=$q 9*$J 4;$J =4}$J+=$I;$L+=$K;a($I,$K,$J,$ L); ($I,$K)=($J,$L)}a($I,$K,$N,$O)}@_;my$T;map{$y=$_;map{ $T.=$D >{$y} >{$_}?$\:' '}( );$T.="\n"}( );print"\e[H$T"}$w= eval{ require Win32::Console::ANSI};$b=$w?'1;7;':"";($j,$u,$s,$t,$a,$n,$o,$h,$c,$k,$p,$e,$r,$l,$C)=split/}/,'Tw*JSK8IAg*PJ[*J@wR}*JR]*QJ[*J'. 'BA*JQK8I*JC}KUz]BAIJT]*QJ[R? R[e]\RI'.'}Tn*JQ]wRAI*JDnR8QAU}wT8KT'. ']n*jei*ejr*qj]*jr*dj@iq[}*jse*jd[n]*jpe*'.'jbi/ki}t8@?pcdnfgvcbrcp'. '?ABKV]]}*JWe*JD[n]*JPe*JC?8B*JE};Vq*OJQ/IP['.'wQ}*JWeOe{n*EERk8;'. 'J*JC}/U*OJd[OI@*BJ*JXn*J>w]U}CWq*OJc8KJ?O[e]U/T*QJP?}*JSe*JCnTe'. 'QIAKJR}*JV]wRAI*J?}T]*RJcJI[\]3;U]Uq*PM[wV]W]WCT*DM*SJ'. 'ZP[Z'. 'PZa[\]UKVgogK9K*QJ[\]n[RI@*EH@IddR[Q[]T]T]T3o[dk*JE'. '[Z\U'. '{T]*JPKTKK]*OJ[QIO[PIQIO[[gUKU\k*JE+J+J5R5AI*EJ00'. 'BCB*'. 'DMKKJIR[Q+*EJ0*EK';sub h{$\ = qw(% x)[int rand 4];map{printf "\e[$b;%dm",int(rand 6) * ($w 0);system( "cls")if$w ;($A,$S)= ($_[1], $ split '}';for( $z=256 ;$z>0; $z =$S){$S*= sleep$_ [2];while ($_[3]&&($ z+=$ S) <=256){ p@,}}("". "32}7D$j"."}AG". "$u}og"."$s}wg"."$t",""."24}("."ij$a"."}1g$n"."}co$o"."}gg$t"."}qc"."$h}"."^g$e"."})ig"."$r", "32}?"."H$p}FG$e}QG$r". "}ZC"."$l", "28}(LC".""."". "$h}:"."j$a}eg". "$c" 22/02/09 Slide 22."}M"."C$k}ZG". "$e"."}"."dg$r","18"."}("

23 Variables Scalars single quantity variables of ANY type Always use $, for both access and declaration Arrays Integer indexed scalar array when using the array as a whole, $ for accessing an array = (1,2,3); print $arr[1]; 22/02/09 Slide 23

24 Hashes Hash ANY SCALAR indexed array of scalars % for a hash as a whole, $ for a hash element %blah = {foo=>bar, 4=>'four', apple=>'orange'}; print $blah{foo}; 22/02/09 Slide 24

25 Loops For and while loops same as C. Also FOREACH loop foreach my $i } foreach my $i (%somehash){ } foreach my $i (keys %somehash){ 22/02/09 Slide 25

26 Lexicals my Used to declare variables to be within the local scope. Otherwise they're global Scope is innermost {} of the current context 22/02/09 Slide 26

27 Functions Declare as sub FUNCTIONNAME{} Where the arguments at? How do you access arguments if they don't have names? 22/02/09 Slide 27

28 The Implicit Perl has a notion of a special 'Implicit' Variable. $_ They get set to be the result of the last computation (ish) to access arguements of a function sub multiply{ my ($x, $y) 22/02/09 Slide 28

29 Modules More modules and libraries than any other language! Search and you shall find. 22/02/09 Slide 29

30 And so fourth Perl is a magical mystical world of amazing possibilities. Once you fully command the power of Perl you can wield it to effortlessly write programs of unbelievable complexity. Try creating a hash table which can take any scalar as index and any scalar of any size in the table itself in C. 22/02/09 Slide 30

CSCI-GA Scripting Languages

CSCI-GA Scripting Languages CSCI-GA.3033.003 Scripting Languages 9/11/2013 Textual data processing (Perl) 1 Announcements If you did not get a PIN to enroll, contact Stephanie Meik 2 Outline Perl Basics (continued) Regular Expressions

More information

CSCI-GA Scripting Languages

CSCI-GA Scripting Languages CSCI-GA.3033.003 Scripting Languages 6/7/2012 Textual data processing (Perl) CS 5142 Cornell University 9/7/13 1 Administrative Announcements Homework 2 due Friday at 6pm. First prelim 9/27, Review on

More information

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

sottotitolo A.A. 2016/17 Federico Reghenzani, Alessandro Barenghi Titolo presentazione Piattaforme Software per la Rete sottotitolo BASH Scripting Milano, XX mese 20XX A.A. 2016/17, Alessandro Barenghi Outline 1) Introduction to BASH 2) Helper commands 3) Control Flow

More information

bash Tests and Looping Administrative Shell Scripting COMP2101 Fall 2017

bash Tests and Looping Administrative Shell Scripting COMP2101 Fall 2017 bash Tests and Looping Administrative Shell Scripting COMP2101 Fall 2017 Command Lists A command is a sequence of commands separated by the operators ; & && and ; is used to simply execute commands in

More information

What is PERL?

What is PERL? Perl For Beginners What is PERL? Practical Extraction Reporting Language General-purpose programming language Creation of Larry Wall 1987 Maintained by a community of developers Free/Open Source www.cpan.org

More information

Scripting Languages Perl Basics. Course: Hebrew University

Scripting Languages Perl Basics. Course: Hebrew University Scripting Languages Perl Basics Course: 67557 Hebrew University אליוט יפה Jaffe Lecturer: Elliot FMTEYEWTK Far More Than Everything You've Ever Wanted to Know Perl Pathologically Eclectic Rubbish Lister

More information

bash Tests and Looping Administrative Shell Scripting COMP2101 Fall 2017

bash Tests and Looping Administrative Shell Scripting COMP2101 Fall 2017 bash Tests and Looping Administrative Shell Scripting COMP2101 Fall 2017 Command Lists A command is a sequence of commands separated by the operators ; & && and ; is used to simply execute commands in

More information

Perl for Biologists. Session 2 March 19, Constants, variables and functions. Jaroslaw Pillardy

Perl for Biologists. Session 2 March 19, Constants, variables and functions. Jaroslaw Pillardy Perl for Biologists Session 2 March 19, 2014 Constants, variables and functions Jaroslaw Pillardy Session 2: Constants, variables and functions Perl for Biologists 1.1 1 "shebang" notation path to the

More information

CSCI-GA Scripting Languages

CSCI-GA Scripting Languages CSCI-GA.3033.003 Scripting Languages 9/20/2013 Context and Modules (Perl) Scripting as Glue 1 Outline Programming in the large Scripting as glue 2 Modules Module = file p/q.pm that starts with declaration

More information

1. Introduction. 2. Scalar Data

1. Introduction. 2. Scalar Data 1. Introduction What Does Perl Stand For? Why Did Larry Create Perl? Why Didn t Larry Just Use Some Other Language? Is Perl Easy or Hard? How Did Perl Get to Be So Popular? What s Happening with Perl Now?

More information

Perl. Interview Questions and Answers

Perl. Interview Questions and Answers and Answers Prepared by Abhisek Vyas Document Version 1.0 Team, www.sybaseblog.com 1 of 13 Q. How do you separate executable statements in perl? semi-colons separate executable statements Example: my(

More information

Pathologically Eclectic Rubbish Lister

Pathologically Eclectic Rubbish Lister Pathologically Eclectic Rubbish Lister 1 Perl Design Philosophy Author: Reuben Francis Cornel perl is an acronym for Practical Extraction and Report Language. But I guess the title is a rough translation

More information

Introduction to Perl. Perl Background. Sept 24, 2007 Class Meeting 6

Introduction to Perl. Perl Background. Sept 24, 2007 Class Meeting 6 Introduction to Perl Sept 24, 2007 Class Meeting 6 * Notes on Perl by Lenwood Heath, Virginia Tech 2004 Perl Background Practical Extraction and Report Language (Perl) Created by Larry Wall, mid-1980's

More information

Unix Scripts and Job Scheduling. Overview. Running a Shell Script

Unix Scripts and Job Scheduling. Overview. Running a Shell Script Unix Scripts and Job Scheduling Michael B. Spring Department of Information Science and Telecommunications University of Pittsburgh spring@imap.pitt.edu http://www.sis.pitt.edu/~spring Overview Shell Scripts

More information

More Perl. CS174 Chris Pollett Oct 25, 2006.

More Perl. CS174 Chris Pollett Oct 25, 2006. More Perl CS174 Chris Pollett Oct 25, 2006. Outline Loops Arrays Hashes Functions Selection Redux Last day we learned about how if-else works in Perl. Perl does not have a switch statement Like Javascript,

More information

CSCI 4152/6509 Natural Language Processing. Perl Tutorial CSCI 4152/6509. CSCI 4152/6509, Perl Tutorial 1

CSCI 4152/6509 Natural Language Processing. Perl Tutorial CSCI 4152/6509. CSCI 4152/6509, Perl Tutorial 1 CSCI 4152/6509 Natural Language Processing Perl Tutorial CSCI 4152/6509 Vlado Kešelj CSCI 4152/6509, Perl Tutorial 1 created in 1987 by Larry Wall About Perl interpreted language, with just-in-time semi-compilation

More information

Intermediate Perl Session Intermediate Perl. map transforming data. sort ranking data. grep extracting data

Intermediate Perl Session Intermediate Perl. map transforming data. sort ranking data. grep extracting data 1.1.2.8.3 Intermediate Perl Session 3 map transforming data sort ranking data grep extracting data use the man pages perldoc f sort perldoc f grep, etc 8/5/2008 1.1.2.8.3 - Intermediate Perl - sort/grep/map

More information

Shells & Shell Programming (Part B)

Shells & Shell Programming (Part B) Shells & Shell Programming (Part B) Software Tools EECS2031 Winter 2018 Manos Papagelis Thanks to Karen Reid and Alan J Rosenthal for material in these slides CONTROL STATEMENTS 2 Control Statements Conditional

More information

Output with printf Input. from a file from a command arguments from the command read

Output with printf Input. from a file from a command arguments from the command read More Scripting 1 Output with printf Input from a file from a command arguments from the command read 2 A script can test whether or not standard input is a terminal [ -t 0 ] What about standard output,

More information

More Scripting and Regular Expressions. Todd Kelley CST8207 Todd Kelley 1

More Scripting and Regular Expressions. Todd Kelley CST8207 Todd Kelley 1 More Scripting and Regular Expressions Todd Kelley kelleyt@algonquincollege.com CST8207 Todd Kelley 1 Regular Expression Summary Regular Expression Examples Shell Scripting 2 Do not confuse filename globbing

More information

Linux Shell Scripting. Linux System Administration COMP2018 Summer 2017

Linux Shell Scripting. Linux System Administration COMP2018 Summer 2017 Linux Shell Scripting Linux System Administration COMP2018 Summer 2017 What is Scripting? Commands can be given to a computer by entering them into a command interpreter program, commonly called a shell

More information

A Crash Course in Perl5

A Crash Course in Perl5 z e e g e e s o f t w a r e A Crash Course in Perl5 Part 1: Basics Zeegee Software Inc. http://www.zeegee.com/ Terms and Conditions These slides are Copyright 2008 by Zeegee Software Inc. They have been

More information

bash, part 3 Chris GauthierDickey

bash, part 3 Chris GauthierDickey bash, part 3 Chris GauthierDickey More redirection As you know, by default we have 3 standard streams: input, output, error How do we redirect more than one stream? This requires an introduction to file

More information

More Scripting Todd Kelley CST8207 Todd Kelley 1

More Scripting Todd Kelley CST8207 Todd Kelley 1 More Scripting Todd Kelley kelleyt@algonquincollege.com CST8207 Todd Kelley 1 Arithmetic Output with printf Input from a file from a command CST8177 Todd Kelley 2 A script can test whether or not standard

More information

Bash command shell language interpreter

Bash command shell language interpreter Principles of Programming Languages Bash command shell language interpreter Advanced seminar topic Louis Sugy & Baptiste Thémine Presentation on December 8th, 2017 Table of contents I. General information

More information

Computational Theory MAT542 (Computational Methods in Genomics) - Part 2 & 3 -

Computational Theory MAT542 (Computational Methods in Genomics) - Part 2 & 3 - Computational Theory MAT542 (Computational Methods in Genomics) - Part 2 & 3 - Benjamin King Mount Desert Island Biological Laboratory bking@mdibl.org Overview of 4 Lectures Introduction to Computation

More information

Shells and Shell Programming

Shells and Shell Programming Shells and Shell Programming 1 Shells A shell is a command line interpreter that is the interface between the user and the OS. The shell: analyzes each command determines what actions are to be performed

More information

Beyond Blocks: Python Session #1

Beyond Blocks: Python Session #1 Beyond Blocks: Session #1 CS10 Spring 2013 Thursday, April 30, 2013 Michael Ball Beyond Blocks : : Session #1 by Michael Ball adapted from Glenn Sugden is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike

More information

Shells and Shell Programming

Shells and Shell Programming Shells and Shell Programming Shells A shell is a command line interpreter that is the interface between the user and the OS. The shell: analyzes each command determines what actions are to be performed

More information

UNIX Shell Programming

UNIX Shell Programming $!... 5:13 $$ and $!... 5:13.profile File... 7:4 /etc/bashrc... 10:13 /etc/profile... 10:12 /etc/profile File... 7:5 ~/.bash_login... 10:15 ~/.bash_logout... 10:18 ~/.bash_profile... 10:14 ~/.bashrc...

More information

Introduction to shell scripting

Introduction to shell scripting Introduction to shell scripting Thomas Röblitz thomasroblitz@usituiono Research Infrastructure Services Group Department for Research Computing (DRC) DRC Course Week, March 25-28, 2014 Outline What is

More information

# or you can even do this if your shell supports your native encoding

# or you can even do this if your shell supports your native encoding NAME SYNOPSIS encoding - allows you to write your script in non-ascii or non-utf8 use encoding "greek"; # Perl like Greek to you? use encoding "euc-jp"; # Jperl! # or you can even do this if your shell

More information

BASH SHELL SCRIPT 1- Introduction to Shell

BASH SHELL SCRIPT 1- Introduction to Shell BASH SHELL SCRIPT 1- Introduction to Shell What is shell Installation of shell Shell features Bash Keywords Built-in Commands Linux Commands Specialized Navigation and History Commands Shell Aliases Bash

More information

Perl Library Functions

Perl Library Functions Perl Library Functions Perl has literally hundreds of functions for all kinds of purposes: file manipulation, database access, network programming, etc. etc. It has an especially rich collection of functions

More information

example: name1=jan name2=mike export name1 In this example, name1 is an environmental variable while name2 is a local variable.

example: name1=jan name2=mike export name1 In this example, name1 is an environmental variable while name2 is a local variable. Bourne Shell Programming Variables - creating and assigning variables Bourne shell use the set and unset to create and assign values to variables or typing the variable name, an equal sign and the value

More information

Lab Instructor : Jean Lai

Lab Instructor : Jean Lai Lab Instructor : Jean Lai Group related statements to perform a specific task. Structure the program (No duplicate codes!) Must be declared before used. Can be invoked (called) as any number of times.

More information

COL100 Lab 2. I semester Week 2, Open the web-browser and visit the page and visit the COL100 course page.

COL100 Lab 2. I semester Week 2, Open the web-browser and visit the page   and visit the COL100 course page. COL100 Lab 2 I semester 2017-18 Week 2, 2017 Objective More familiarisation with Linux and its standard commands Part 1 1. Login to your system and open a terminal window. 2. Open the web-browser and visit

More information

COMS 3101 Programming Languages: Perl. Lecture 2

COMS 3101 Programming Languages: Perl. Lecture 2 COMS 3101 Programming Languages: Perl Lecture 2 Fall 2013 Instructor: Ilia Vovsha http://www.cs.columbia.edu/~vovsha/coms3101/perl Lecture Outline Control Flow (continued) Input / Output Subroutines Concepts:

More information

CS Unix Tools & Scripting

CS Unix Tools & Scripting Cornell University, Spring 2014 1 February 24, 2014 1 Slides evolved from previous versions by Hussam Abu-Libdeh and David Slater A note on awk for (item in array) The order in which items are returned

More information

IT441. Subroutines. (a.k.a., Functions, Methods, etc.) DRAFT. Network Services Administration

IT441. Subroutines. (a.k.a., Functions, Methods, etc.) DRAFT. Network Services Administration IT441 Network Services Administration Subroutines DRAFT (a.k.a., Functions, Methods, etc.) Organizing Code We have recently discussed the topic of organizing data (i.e., arrays and hashes) in order to

More information

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS

More information

I/O and Shell Scripting

I/O and Shell Scripting I/O and Shell Scripting File Descriptors Redirecting Standard Error Shell Scripts Making a Shell Script Executable Specifying Which Shell Will Run a Script Comments in Shell Scripts File Descriptors Resources

More information

Subroutines. Subroutines. The Basics. aka: user-defined functions, methods, procdures, sub-procedures, etc etc etc.

Subroutines. Subroutines. The Basics. aka: user-defined functions, methods, procdures, sub-procedures, etc etc etc. Subroutines Subroutines aka: user-defined functions, methods, procdures, sub-procedures, etc etc etc We ll just say Subroutines. "Functions" generally means built-in functions perldoc perlsub The Basics

More information

Processes and Shells

Processes and Shells Shell ls pico httpd CPU Kernel Disk NIC Processes Processes are tasks run by you or the OS. Processes can be: shells commands programs daemons scripts Shells Processes operate in the context of a shell.

More information

Perl (5 Days Content)

Perl (5 Days Content) Perl (5 Days Content) Pre-requisites: Knowledge of any programming language ( C / C++ / Shell Scripting) Objective of the Course: The participants should be in a position to understand Perl Scripts written

More information

CpSc 111 Lab 3 Integer Variables, Mathematical Operations, & Redirection

CpSc 111 Lab 3 Integer Variables, Mathematical Operations, & Redirection CpSc 111 Lab 3 Integer Variables, Mathematical Operations, & Redirection Overview By the end of the lab, you will be able to: declare variables perform basic arithmetic operations on integer variables

More information

Programming Concepts. Perl. Adapted from Practical Unix and Programming Hunter College

Programming Concepts. Perl. Adapted from Practical Unix and Programming Hunter College Programming Concepts Perl Adapted from Practical Unix and Programming Hunter College Copyright 2006 2009 Stewart Weiss About Perl Perl was written by Larry Wall, and stands for either Practical Extraction

More information

Python 1: Introduction to Python 1 / 19

Python 1: Introduction to Python 1 / 19 Python 1: Introduction to Python 1 / 19 Python Python is one of many scripting languages. Others include Perl, Ruby, and even the Bash/Shell programming we've been talking about. It is a script because

More information

The Power of Perl. Perl. Perl. Change all gopher to World Wide Web in a single command

The Power of Perl. Perl. Perl. Change all gopher to World Wide Web in a single command The Power of Perl Perl Change all gopher to World Wide Web in a single command perl -e s/gopher/world Wide Web/gi -p -i.bak *.html Perl can be used as a command Or like an interpreter UVic SEng 265 Daniel

More information

Examples of Using the ARGV Array. Loop Control Operators. Next Operator. Last Operator. Perl has three loop control operators.

Examples of Using the ARGV Array. Loop Control Operators. Next Operator. Last Operator. Perl has three loop control operators. Examples of Using the ARGV Array # mimics the Unix echo utility foreach (@ARGV) { print $_ ; print \n ; # count the number of command line arguments $i = 0; foreach (@ARGV) { $i++; print The number of

More information

CS 360 Programming Languages Interpreters

CS 360 Programming Languages Interpreters CS 360 Programming Languages Interpreters Implementing PLs Most of the course is learning fundamental concepts for using and understanding PLs. Syntax vs. semantics vs. idioms. Powerful constructs like

More information

Linux shell scripting Getting started *

Linux shell scripting Getting started * Linux shell scripting Getting started * David Morgan *based on chapter by the same name in Classic Shell Scripting by Robbins and Beebe What s s a script? text file containing commands executed as a unit

More information

IT441. Network Services Administration. Data Structures: Arrays

IT441. Network Services Administration. Data Structures: Arrays IT441 Network Services Administration Data Structures: Arrays Data Types Remember there are three basic data types in Perl o Numeric o String o Boolean (Logical) I differentiate between data types and

More information

Introduction to Programming (Java) 2/12

Introduction to Programming (Java) 2/12 Introduction to Programming (Java) 2/12 Michal Krátký Department of Computer Science Technical University of Ostrava Introduction to Programming (Java) 2008/2009 c 2006 2008 Michal Krátký Introduction

More information

COMP284 Scripting Languages Lecture 3: Perl (Part 2) Handouts

COMP284 Scripting Languages Lecture 3: Perl (Part 2) Handouts COMP284 Scripting Languages Lecture 3: Perl (Part 2) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3). cs3157: another C lecture (mon-21-feb-2005) C pre-processor (1). today: C pre-processor command-line arguments more on data types and operators: booleans in C logical and bitwise operators type conversion

More information

While Statement Examples. While Statement (35.15) Until Statement (35.15) Until Statement Example

While Statement Examples. While Statement (35.15) Until Statement (35.15) Until Statement Example While Statement (35.15) General form. The commands in the loop are performed while the condition is true. while condition one-or-more-commands While Statement Examples # process commands until a stop is

More information

Perl Scripting. Students Will Learn. Course Description. Duration: 4 Days. Price: $2295

Perl Scripting. Students Will Learn. Course Description. Duration: 4 Days. Price: $2295 Perl Scripting Duration: 4 Days Price: $2295 Discounts: We offer multiple discount options. Click here for more info. Delivery Options: Attend face-to-face in the classroom, remote-live or on-demand streaming.

More information

INTRODUCTION TO SHELL SCRIPTING Dr. Jeffrey Frey University of Delaware, IT

INTRODUCTION TO SHELL SCRIPTING Dr. Jeffrey Frey University of Delaware, IT INTRODUCTION TO SHELL SCRIPTING Dr. Jeffrey Frey University of Delaware, IT GOALS BASIC What is shell scripting? What makes shell scripting useful? What should you know already GOALS PART 1 Script layout/design

More information

Process Management forks, bombs, zombies, and daemons! Lecture 5, Hands-On Unix System Administration DeCal

Process Management forks, bombs, zombies, and daemons! Lecture 5, Hands-On Unix System Administration DeCal Process Management forks, bombs, zombies, and daemons! Lecture 5, Hands-On Unix System Administration DeCal 2012-10-01 what is a process? an abstraction! you can think of it as a program in the midst of

More information

Shell Programming (bash)

Shell Programming (bash) Shell Programming Shell Programming (bash) Commands run from a file in a subshell A great way to automate a repeated sequence of commands. File starts with #!/bin/bash absolute path to the shell program

More information

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

Shell scripting and system variables. HORT Lecture 5 Instructor: Kranthi Varala Shell scripting and system variables HORT 59000 Lecture 5 Instructor: Kranthi Varala Text editors Programs built to assist creation and manipulation of text files, typically scripts. nano : easy-to-learn,

More information

PESIT Bangalore South Campus

PESIT Bangalore South Campus INTERNAL ASSESSMENT TEST - III Date : 09-11-2015 Marks : 0 Subject & Code : USP & 15CS36 Class : III ISE A & B Name of faculty : Prof. Ajoy Kumar Note: Solutions to ALL Questions Questions 1 a. Explain

More information

Script Programming Systems Skills in C and Unix

Script Programming Systems Skills in C and Unix Script Programming with Perl II 15-123 Systems Skills in C and Unix Subroutines sub sum { return $a + $b; } So we can call this as: $a = 12; $b = 10; $sum = sum(); print the sum is $sum\n ; Passing Arguments

More information

Operational Semantics of Cool

Operational Semantics of Cool Operational Semantics of Cool Lecture 22 Dr. Sean Peisert ECS 142 Spring 2009 1 Status Project 3 due on Friday Project 4 assigned on Friday. Due June 5, 11:55pm Office Hours this week are Wed at 4pm and

More information

CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection

CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection Overview By the end of the lab, you will be able to: declare variables perform basic arithmetic operations on integer variables

More information

Introduction to Perl Session 6. special variables subroutines Introduction to Perl

Introduction to Perl Session 6. special variables subroutines Introduction to Perl 1.0.1.8.6 Introduction to Perl Session 6 special variables subroutines 6/17/2008 1.0.1.8.6 - Introduction to Perl - Special Variables and Subroutines 1 I/O Recap file handles are created using open(f,$file);

More information

Homework 4 Due Friday, 10/3/08

Homework 4 Due Friday, 10/3/08 Homework 4 Due Friday, 10/3/08 Please turn in your homework solutions by the beginning of class to the dropoff folder on vpn.cs.pomona.edu in directory /common/cs/cs131/dropbox. Make sure that all of your

More information

Hands-On Perl Scripting and CGI Programming

Hands-On Perl Scripting and CGI Programming Hands-On Course Description This hands on Perl programming course provides a thorough introduction to the Perl programming language, teaching attendees how to develop and maintain portable scripts useful

More information

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

BASH and command line utilities Variables Conditional Commands Loop Commands BASH scripts BASH and command line utilities Variables Conditional Commands Loop Commands BASH scripts SCOMRED, October 2018 Instituto Superior de Engenharia do Porto (ISEP) Departamento de Engenharia Informática(DEI)

More information

Bash scripting Tutorial. Hello World Bash Shell Script. Super User Programming & Scripting 22 March 2013

Bash scripting Tutorial. Hello World Bash Shell Script. Super User Programming & Scripting 22 March 2013 Bash scripting Tutorial Super User Programming & Scripting 22 March 2013 Hello World Bash Shell Script First you need to find out where is your bash interpreter located. Enter the following into your command

More information

Shell Programming. Introduction to Linux. Peter Ruprecht Research CU Boulder

Shell Programming. Introduction to Linux. Peter Ruprecht  Research CU Boulder Introduction to Linux Shell Programming Peter Ruprecht peter.ruprecht@colorado.edu www.rc.colorado.edu Downloadable Materials Slides and examples available at https://github.com/researchcomputing/ Final_Tutorials/

More information

Bash Script. CIRC Summer School 2015 Baowei Liu

Bash Script. CIRC Summer School 2015 Baowei Liu Bash Script CIRC Summer School 2015 Baowei Liu Filename Expansion / Globbing Expanding filenames containing special characters Wild cards *?, not include... Square brackets [set]: - Special characters:!

More information

Environments

Environments Environments PLAI Chapter 6 Evaluating using substitutions is very inefficient To work around this, we want to use a cache of substitutions. We begin evaluating with no cached substitutions, then collect

More information

CSE 341 Section 7. Eric Mullen Spring Adapted from slides by Nicholas Shahan, Dan Grossman, and Tam Dang

CSE 341 Section 7. Eric Mullen Spring Adapted from slides by Nicholas Shahan, Dan Grossman, and Tam Dang CSE 341 Section 7 Eric Mullen Spring 2017 Adapted from slides by Nicholas Shahan, Dan Grossman, and Tam Dang Outline Interpreting LBI (Language Being Implemented) Assume Correct Syntax Check for Correct

More information

Princeton University COS 333: Advanced Programming Techniques A Subset of PHP

Princeton University COS 333: Advanced Programming Techniques A Subset of PHP Princeton University COS 333: Advanced Programming Techniques A Subset of PHP Program Structure -----------------------------------------------------------------------------------

More information

Functions in C C Programming and Software Tools

Functions in C C Programming and Software Tools Functions in C C Programming and Software Tools N.C. State Department of Computer Science Functions in C Functions are also called subroutines or procedures One part of a program calls (or invokes the

More information

Introduction to Perl. c Sanjiv K. Bhatia. Department of Mathematics & Computer Science University of Missouri St. Louis St.

Introduction to Perl. c Sanjiv K. Bhatia. Department of Mathematics & Computer Science University of Missouri St. Louis St. Introduction to Perl c Sanjiv K. Bhatia Department of Mathematics & Computer Science University of Missouri St. Louis St. Louis, MO 63121 Contents 1 Introduction 1 2 Getting started 1 3 Writing Perl scripts

More information

Obfuscator-LLVM. - Software Obfuscation for the Masses. area41 // Zürich //

Obfuscator-LLVM. - Software Obfuscation for the Masses. area41 // Zürich // Obfuscator-LLVM - Software Obfuscation for the Masses area41 // Zürich // 02-06-2014 Who? Who? Pascal Junod (@cryptopathe), Julien Rinaldini (@pyknite), Johan Wehrli (@jowehrli) // HEIG-VD Julie Michielin

More information

Compilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam

Compilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam Compilers Type checking Yannis Smaragdakis, U. Athens (original slides by Sam Guyer@Tufts) Summary of parsing Parsing A solid foundation: context-free grammars A simple parser: LL(1) A more powerful parser:

More information

Basics. proper programmers write commands

Basics. proper programmers write commands Scripting Languages Basics proper programmers write commands E.g. mkdir john1 rather than clicking on icons If you write a (set of) command more that once you can put them in a file and you do not need

More information

Perl for Biologists. Arrays and lists. Session 4 April 2, Jaroslaw Pillardy. Session 4: Arrays and lists Perl for Biologists 1.

Perl for Biologists. Arrays and lists. Session 4 April 2, Jaroslaw Pillardy. Session 4: Arrays and lists Perl for Biologists 1. Perl for Biologists Session 4 April 2, 2014 Arrays and lists Jaroslaw Pillardy Session 4: Arrays and lists Perl for Biologists 1.1 1 if statement if(condition1) statement; elsif(condition2) statement;

More information

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

Exercise sheet 1 To be corrected in tutorials in the week from 23/10/2017 to 27/10/2017 Einführung in die Programmierung für Physiker WS 207/208 Marc Wagner Francesca Cuteri: cuteri@th.physik.uni-frankfurt.de Alessandro Sciarra: sciarra@th.physik.uni-frankfurt.de Exercise sheet To be corrected

More information

C-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga

C-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga C-Programming CSC209: Software Tools and Systems Programming Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Adapted from Dan Zingaro s 2015 slides. Week 2.0 1 / 19 What

More information

Advanced Web Design. Unit 8 The Basics of Perl

Advanced Web Design. Unit 8 The Basics of Perl Advanced Web Design Unit 8 The Basics of Perl Eduoncloud.com Page 1 Origins and Uses of Perl Perl was developed in 1987 by Larry Wall. What is perl Practical Extraction and Report Language Goal: to expand

More information

COMS 3101 Programming Languages: Perl. Lecture 3

COMS 3101 Programming Languages: Perl. Lecture 3 COMS 3101 Programming Languages: Perl Lecture 3 Fall 2013 Instructor: Ilia Vovsha http://www.cs.columbia.edu/~vovsha/coms3101/perl Lecture Outline Array / Hash manipulation (continued) Pattern Matching

More information

Lecture 12. PHP. cp476 PHP

Lecture 12. PHP. cp476 PHP Lecture 12. PHP 1. Origins of PHP 2. Overview of PHP 3. General Syntactic Characteristics 4. Primitives, Operations, and Expressions 5. Control Statements 6. Arrays 7. User-Defined Functions 8. Objects

More information

SISTEMI EMBEDDED. The C Pre-processor Fixed-size integer types Bit Manipulation. Federico Baronti Last version:

SISTEMI EMBEDDED. The C Pre-processor Fixed-size integer types Bit Manipulation. Federico Baronti Last version: SISTEMI EMBEDDED The C Pre-processor Fixed-size integer types Bit Manipulation Federico Baronti Last version: 20160302 The C PreProcessor CPP (1) CPP is a program called by the compiler that processes

More information

Shell Programming (Part 2)

Shell Programming (Part 2) i i Systems and Internet Infrastructure Security Institute for Networking and Security Research Department of Computer Science and Engineering Pennsylvania State University, University Park, PA Shell Programming

More information

CSE 390a Lecture 5. Intro to shell scripting

CSE 390a Lecture 5. Intro to shell scripting CSE 390a Lecture 5 Intro to shell scripting slides created by Marty Stepp, modified by Jessica Miller & Ruth Anderson http://www.cs.washington.edu/390a/ 1 2 Lecture summary basic script syntax and running

More information

Chapter 11 :: Functional Languages

Chapter 11 :: Functional Languages Chapter 11 :: Functional Languages Programming Language Pragmatics Michael L. Scott Copyright 2016 Elsevier 1 Chapter11_Functional_Languages_4e - Tue November 21, 2017 Historical Origins The imperative

More information

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer. The Compiler So Far CSC 4181 Compiler Construction Scanner - Lexical analysis Detects inputs with illegal tokens e.g.: main 5 (); Parser - Syntactic analysis Detects inputs with ill-formed parse trees

More information

Bash shell programming Part II Control statements

Bash shell programming Part II Control statements Bash shell programming Part II Control statements Deniz Savas and Michael Griffiths 2005-2011 Corporate Information and Computing Services The University of Sheffield Email M.Griffiths@sheffield.ac.uk

More information

NCAR-Developed Tools. Bill Anderson and Marc Genty National Center for Atmospheric Research HUF 2017

NCAR-Developed Tools. Bill Anderson and Marc Genty National Center for Atmospheric Research HUF 2017 NCAR-Developed Tools Bill Anderson and Marc Genty National Center for Atmospheric Research HUF 2017 1 Introduction Over the years, we ve benefited from tools that others have developed In this talk, we

More information

CS3157: Advanced Programming. Outline

CS3157: Advanced Programming. Outline CS3157: Advanced Programming Lecture #8 Feb 27 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline More c Preprocessor Bitwise operations Character handling Math/random Review for midterm Reading: k&r ch

More information

First steps on Linux and programming

First steps on Linux and programming First steps on Linux and programming Adrien Poteaux CRIStAL, Université de Lille Year 2017-2018 This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. http://creativecommons.org/licenses/by-nc-sa/3.0/

More information

PERL - FUNCTIONS REFERENCES

PERL - FUNCTIONS REFERENCES PERL - FUNCTIONS REFERENCES http://www.tutorialspoint.com/perl/perl_function_references.htm Copyright tutorialspoint.com Here is the list of all the important functions supported by standard Perl. abs

More information

# use a BEGIN block so we print our plan before MyModule is loaded BEGIN { plan tests => 14, todo => [3,4] }

# use a BEGIN block so we print our plan before MyModule is loaded BEGIN { plan tests => 14, todo => [3,4] } NAME SYNOPSIS Test - provides a simple framework for writing test scripts use strict; use Test; # use a BEGIN block so we print our plan before MyModule is loaded BEGIN { plan tests => 14, todo => [3,4]

More information

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

Log into Linux Reminders: Homework 1 due today; Homework 2 due on Thursday Questions? Lecture 4 Log into Linux Reminders: Homework 1 due today; Homework 2 due on Thursday Questions? Tuesday, September 8 CS 375 UNIX System Programming - Lecture 4 1 Outline Exercise from last lecture More

More information

Regular Expressions. Todd Kelley CST8207 Todd Kelley 1

Regular Expressions. Todd Kelley CST8207 Todd Kelley 1 Regular Expressions Todd Kelley kelleyt@algonquincollege.com CST8207 Todd Kelley 1 Our standard.bashrc and.bash_profile (or.profile) Our standard script header Regular Expressions 2 [ -z "${PS1-}" ] &&

More information