Unix Power Use. Martti Louhivuori. Spring School in Computational Chemistry 2013 PRACE Advanced Training CSC

Size: px
Start display at page:

Download "Unix Power Use. Martti Louhivuori. Spring School in Computational Chemistry 2013 PRACE Advanced Training CSC"

Transcription

1 Unix Power Use Martti Louhivuori Spring School in Computational Chemistry 2013 PRACE Advanced Training CSC

2 Shell Scripting Martti Louhivuori CSC Tieteen tietotekniikan keskus Oy CSC IT Center for Science Ltd.

3 Introduction shell scripting is the art of writing scripts that can automate repetitive tasks here we present BASH and discuss how it can be used as a general programming languages

4 Different shells sh Bourne shell csh/tcsh C shell ksh Korn shell zsh Z shell bash Bourne again shell sh successor that includes csh and ksh features

5 When NOT to use a shell script? resource or compute intensive large-scale applications complex datastructures lot s of I/O, need libraries, floating point arithmetic, use Perl, Python or even C or Fortran instead

6 When to use a shell script? glue together Unix commands to automate repetitive tasks awk, bc, more, less, paste, simple applications that do not need lots of resources fancy scripts for batch jobs

7 How to write a script? put commands that you would execute on the command-line in a file $ cat hello.sh echo "Hello world!" echo "... this is my first script." $ bash hello.sh Hello world!... this is my first script.

8 Pipe magic commands can be chained together using a pipe $ cat hello.sh grep my echo "... this is my first script." $./configure --help less the output of the 1st command (left) is used as the input of the 2nd command (right) arbitrary number of pipes can be used

9 Pipe magic with files output can be redirected to a file with > overwrite >> append input can be read from a file with < read $ echo "Hello world!" > hello $ echo "... what's up?" >> hello $ cat < hello Hello world!... what's up?

10 Pipes & streams three special streams always opened: stdin 0< keyboard stdout 1> stderr 2> screen error messages (on screen) stdout and stderr can be joined with &> or &>> M>&N redirects file descriptor M to N i.e. 2>&1 joins stderr and stdout

11 Pipes & streams # separate stdout & stderr $./myprogram > output 2> errors # joined stdout & stderr $./myprogram &> output+errors # one-time redirect $./myprogram > filename 2>&1 # permanent redirect $ exec 2>&1 $./myprogram > filename # swap stdout and stderr $./myprogram 3>&2 2>&1 1>&3

12 Executable script, Sha-Bang! add a shebang to the script to define the shell that executes it #!shell-binary hello.sh: #!/bin/bash echo "Hello world!" $ chmod u+x hello.sh $./hello.sh Hello world!

13 Comments anything after a # is treated as a comment can be added as separate line, or at the end of a line hello.sh: #!/bin/bash # let's greet the world... echo "Hello world!" # cliche $ bash hello.sh Hello world!

14 Variables like other programming languages bash has variables variables can be set with name=value to use the variable precede the name with $, e.g. $name you may need to enclose the variable name in curly brackets: ${name}

15 Variable expansion $ name=max $ echo "Hi $name!" Hi Max! $ name="sir Max"; d=sun $ echo "Dear $name," $ echo "today is ${d}day." Dear Sir Max, today is Sunday.

16 Variable types there are two types of variables strings integers (no native floating point type!) additionally variables can be read-only an array by default variables can hold any data we assign to it this can be limited with "declare"

17 declare declare an integer variable declare I name=value declare a read-only variable declare r name=value print the variable attributes declare p name

18 Arrays bash supports 1D arrays defining an array element-by-element: myarray[123]=456 as a list: myarray=( apple 1 ) elements do not need to be contiguous value accessed as ${myarray[123]} does NOT work without the curly brackets!

19 Arrays special array syntax ${myarray[*]} all items ${!myarray[*]} all indexes ${#myarray[*]} number of items ${#myarray[0]} length of item 0 ${#myarray[1]} length of item 1

20 Command line arguments command line arguments are stored as special variables $# number of arguments all arguments $0 name of script $1 first argument $2 second argument

21 Command line arguments cmd-args.sh: #!/bin/bash echo "args: echo "name: $0" echo "1st argument: $1" echo "3rd argument: $3" $ bash cmd-args.sh one two three args: one two three name: cmd-args.sh 1st argument: one 3rd argument: three

22 Quotations single quotes (') preserve literal values $ a='hello!' $ echo '$a' $a double quotes (") preserve literal values, except for: $ ` \ $ echo "$a" hello! $ echo "$a \" " hello! "

23 Command substitution the output of a command can be used in a script with $(command) (or `command`) $(command) is substituted with the output of command just like a variable would be $ echo "Today is $(date)." Today is Fri Aug 26 10:58:03 EEST $ b=20.1 $ a=$(echo "$b*10.0" bc l) $ echo $a

24 Arithmetics simple arithmetics performed using: (( expression )) let "expression" variable and command expansion done on expression $ not needed for variables in expression $ a=10 $ (( c = a - 4 )) $ echo $c 6 $ let "a += 3" $ echo $a 13 $ echo $a $ (( a++ )) 14

25 Arithmetic expansion $(( expression )) replaced by value of expression $ a=10; b=20 $ echo $(( a + b )) 30 $ echo "$a x $b = $(( a * b ))" 10 x 20 = 200 (( expression )) used for if and for constructs $ if (( $DEBUG $MODE == "d" )) then echo "debug mode ON" fi

26 Arithmetic operators Operator Meaning + - addition, subtraction * / % multiplication, division, remainder ** exponentiation VAR++ VAR-- variable post-increment and post-decrement ++VAR --VAR variable pre-increment and pre-decrement <= >= < > comparison operators ==!= equality and inequality && logical AND logical OR! ~ logical and bitwise negation & bitwise AND ^ bitwise exclusive OR bitwise OR << >> left and right bitwise shifts expr? expr : expr conditional evaluation = *= /= %= assignment operations += -= <<= >>= &= ^= =

27 Conditional if statements basic form: if test-commands then do-stuff elif test-commands then do-stuff else $ if [[ 1 eq 1 ]] then echo A else echo B fi A fi do-stuff $ [[ 1 eq 1 ]] && echo A echo B A

28 Test commands four ways to do this (yes really ) test command or [ ] single brackets [[ ]] double brackets (( )) arithmetic expansion double brackets are safer than test or single brackets operators for strings, integers, files and Boolean algebra

29 [[ ]] file test operators [[ -e name ]] file exist [[ -f name ]] is a regular file [[ -d name ]] is a directory [[ -s name ]] is size of file not zero [[ -r name ]] file has read permission [[ -w name ]] file has write permission [[ -x name ]] file has execute permission

30 [[ ]] string operators [[ "s1" == "s2" ]] string equality [[ "s1"!= "s2" ]] string inequality [[ "s1" < "s2" ]] string lexiographic before [[ "s1" > "s2" ]] string lexiographic after [[ "s1" =~ "s2" ]] regular expression match [[ -z "s1" ]] string has zero length [[ -n "s1" ]] string has non-zero length

31 [[ ]] integer operators [[ 1 eq 2 ]] equality [[ 1 ne 2 ]] non-equality [[ 1 lt 2 ]] less than [[ 1 gt 2 ]] more than [[ 1 -le 2 ]] less than or equal [[ 1 -ge 2 ]] greater than or equal

32 [[ ]] Boolean algebra [[ A B ]] (logical) A or B [[ A && B ]] (logical) A and B [[! A ]] not A

33 Conditional example xor.sh: #!/bin/bash if [[ ($1!= $2) && \ ( $1 $2 ) ]] then echo True else echo False fi $ bash xor.sh 1 0 True $ bash xor.sh 1 1 False backslash can be used to continue the command on the next line

34 Case branch code by matching the value of a variable against expression(s) case "$variable" in expr1) commands... ;; expr2) commands... ;; *) default commands... ;; esac each block terminated with ;; always true!

35 Case example case.sh: $ bash case.sh Z #!/bin/bash uppercase letter DEBUG=0 $ bash case.sh 77 case "$1" in number -d --debug) $ bash case.sh f! DEBUG=1 something else ;; $ bash case.sh --debug [0-9]*) debug mode ON echo "number" ;; [[:upper:]]) echo "uppercase letter" ;; *) echo "something else" ;; esac (( $DEBUG )) && echo "debug mode ON"

36 Loops for loops over words in a string for name in Alice Bob Charlie or over numerical indeces for ((i=0; i<10; i++)) HUOM: {0..10} continue jumps to next iteration break steps out of the loop while, until

37 Loops over words loop.sh: #!/bin/bash for name in Alice Bob "Charlie D" do echo "Who? $name" done $ bash loop.sh Who? Alice Who? Bob Who? Charlie D

38 Loops over files loop-files.sh: #!/bin/bash for f in *.sh do l=$(wc $f awk '{ print $1 }') echo "$f has $l lines" done $ bash loop-files.sh loop-args.sh has 7 lines loop-files.sh has 8 lines

39 Loops over arguments loop-args.sh: #!/bin/bash for arg in do echo $arg done quotes needed to handle word splitting correctly! $ bash loop-args.sh one two "3 4" one two 3 4

40 Loops over integers loop-int.sh: #!/bin/bash for ((i=0; i<4; i++)) do echo part-$i done $ bash loop-int.sh part-0 part-1 part-2 part-3

41 Loops while loop-while.sh: #!/bin/bash i=0 while [[ $i lt 4 ]] do echo part-$i let "i += 1" done $ bash loop-while.sh part-0 part-1 part-2 part-3

42 Functions (limited) support for functions funcs-hello.sh: #!/bin/bash hello () { echo "Funky hello!" } echo "calling function hello()..." hello call $ bash funcs-hello.sh calling function hello()... Funky hello! declaration must be before call! declaration

43 Variables scope bash has three scopes for variables: local, global and environment variables local variables are local to current codeblock set with: local var=value use local variables in functions! global variables are global in current shell set with: var=value

44 Variables scope environment variables are inherited by all launched sub-shells set with: export var=value changes in value are not passed back! by convention, ALL_CAPS used for names

45 Variables scope variables.sh: #!/bin/bash scopetest() { local lvar=20 echo "---in function---" echo "lvar: $lvar" echo " var: $var" echo "EVAR: $EVAR" } var=30 export EVAR=40 scopetest echo "---in main scope---" echo "lvar: $lvar" echo " var: $var" echo "EVAR: $EVAR" bash print-variables.sh print-variables.sh: #!/bin/bash echo "---in next shell---" echo "lvar: $lvar" echo " var: $var" echo "EVAR: $EVAR"

46 Variables scope $ bash variables.sh ---in function--- lvar: 20 var: 30 EVAR: in main scope--- lvar: var: 30 EVAR: in next shell--- lvar: var: EVAR: 40 undefined!

47 Functions input funcs-input.sh: #!/bin/bash addup() { local total=0 while [[ $# -gt 0 ]] do case "$1" in [0-9]*) let "total += $1" ;; *) echo "invalid argument: $1" >&2 ;; esac shift done echo "Grand total: $total" } addup addup 3 8 foo input parameters work like command-line arguments $ bash funcs-input.sh Grand total: 22 invalid argument: foo Grand total: 11 $ bash funcs-input.sh 2> /dev/null Grand total: 22 Grand total: 11

48 Functions output no direct way to get output! ;( return value of function is 0 success nonzero failure options are global variable (not recommended but fast) command substitution, i.e. echo output (slow?) output variable name passed as input

49 Functions - output # set global out_a(){ val_a=$1 } # command subst out_b(){ echo $1 } # pass output var name out_c(){ eval $1='$2' } $ out_a 123 $ echo $val_a 123 $ val_b=$(out_b 123) $ echo $val_b 123 $ out_c val_c 123 $ echo $val_c 123 eval will evaluate the line after shell expansions

50 Here documents pipe an arbitrary length text block spanning over multiple lines to a command $ command << END... multiple lines of text... END same as command < file where file includes the input above END is an arbitrary tag that marks the end of input

51 Here documents heredoc.sh: cat << EndBlock A here document can be used to print out instructions using cat. It can also be used to steer an interactive program as shown below... EndBlock gnuplot << EOF f(x)=1/x plot f(x) pause 2 EOF

52 Here documents $ bash heredoc.sh A here document can be used to print out instructions using cat. It can also be used to steer an interactive program as shown below...

53 Further information on-line, free (as in beer) resources Bash guide for Beginners Advanced Bash-Scripting Guide BASH FAQ GNU Bash Reference Manual

54 Further information books Learning the Bash Shell (O Reilly) Bash Cookbook (O Reilly) Pro Bash Programming: Scripting the GNU/Linux Shell

55 Make Martti Louhivuori (Jura Tarus)

56 Why make? Module B Module A Module C Program program separated into several files multiple interdependant modules compilation and linking becomes easily a nightmare especially when developing the program!

57 Why make? when code has been modified, there are two approaches to compile the program: re-compile everything too slow keep records and re-compile only what is needed too much work make makes life easier by taking care of all the book keeping

58 Makefile defines: work-flow(s) for producing target(s) dependencies of each target library paths, compiler flags etc. directives for conditional definitions etc. # starts a comment usually called Makefile other choices: makefile, GNUmakefile

59 RULE Basic syntax name (usually filename) list of files / rules target: dependencies recipe... commands to execute Note: use tabs instead of spaces to example: indent recipes! foo.o: foo.c bar.h # module foo cc -c foo.c clean: rm *.o # remove all

60 Basic syntax target usually the file that is produced by the recipe name of an action also commonly used for example: clean, distclean dependencies a list of (source) files needed by the recipe may also be other targets recipe a list of commands to execute to make target

61 Logic of make read general macro definitions etc. call the rule for target check when dependencies were changed if any of the dependencies have changed, the target is re-built according to the recipe dependencies may also be targets for other rules in that case, make calls those rules

62 Simple example hello: main.o sub1.o sub2.o sub3.o f90 -o hello main.o sub1.o sub2.o sub3.o main.o: main.f90 f90 -c main.f90 sub1.o: sub1.f90 f90 -c sub1.f90 sub2.o: sub2.f90 f90 -c sub2.f90 sub3.o: sub3.f90 f90 -c sub3.f90 clean: rm hello main.o sub1.o sub2.o sub3.o

63 Which target? by default, the first target is called hello in the previous example target can be also specified when running make make target make clean make main.o

64 Variables contain a string of text variable = value substituted in-place when referenced $(variable) value sometimes also called macros shell variables are also available in the makefile $(HOME), $(USER),

65 Two flavors of variables in GNU make recursive variables defined as: foo = bar expanded when referenced simple / constant variables defined as: foo := bar expanded when defined foo = $(bar) bar = $(ugh) ugh = Huh? $(foo) Huh? x := foo y := $(x) bar x = later $(x) later $(y) foo bar

66 Variables by convention variables are name in ALL- CAPS in the previous example we could have used a variable to store the names of all objects OBJ = main.o sub1.o sub2.o sub3.o

67 Simple example revisited OBJ = main.o sub1.o sub2.o sub3.o hello: $(OBJ) f90 -o hello $(OBJ) main.o: main.f90 f90 -c main.f90 sub1.o: sub1.f90 f90 -c sub1.f90 sub2.o: sub2.f90 f90 -c sub2.f90 sub3.o: sub3.f90 f90 -c sub3.f90 clean: rm hello $(OBJ)

68 Common variables some common variables CC CFLAGS FC FCFLAGS LDFLAGS OBJ SRC

69 Special variables $< name of the target client: client.c $(CC) client.c -o name of the first dependency client: client.c $(CC) $< -o

70 Special variables $+ $^ $? list of all dependencies list of all dependencies (duplicates removed) list of dependencies more recent than target client: client.c $(CC) $+ -o

71 Special variables $* common prefix shared by the target and the dependencies client: client.c $(CC) -c -o $*.o $*.c

72 Special characters / continues a line # starts a executes a command quietly by default, make echos all commands executed this can be prevented by at the beginning of the quiet echo quiet echo echo normal echo echo normal echo normal echo

73 Special characters if there is an error executing a command, make stops this can be prevented by using a sign at the beginning of a command clean: -rm hello -rm $(OBJ)

74 Implicit rules one can use special characters to define an implicit rule e.g. quite often target and dependencies share the name (different extensions) define an implicit rule compiling an object file from a Fortran 90 source code file %.o: %.f90 $(F90) $(FFLAGS) -c -o $@ $<

75 Example revisited again OBJ = main.o sub1.o sub2.o sub3.o # implicit rule for compiling f90 files %.o: %.f90 f90 -c -o $@ $< hello: $(OBJ) f90 -o hello $(OBJ) clean: rm hello $(OBJ)

76 Built-in functions GNU make has also built-in functions for a complete list see: strip, patsubst, sort, dir, suffix, basename, wildcard, general syntax $(function arguments)

77 Command line options -j parallel execution -n dry-run shows the command, but does not execute them -p print defaults shows default rules and values for variables before execution -s silent-run do not print commands as they are executed

78 Command line options variables can also be defined from the command line make CC=gcc CFLAGS=-O3 g foobar

79 Complete example SRC = main.f90 sub1.f90 sub2.f90 sub3.f90 OBJ = $(patsubst %.f90, %.o, $(SRC)) F90 = gfortran FFLAGS = DEST = bin # implicit rule for compiling f90 files %.o: %.f90 $(F90) $(FFLAGS) -c -o $@ $< hello: $(DEST)/hello $(DEST)/hello: $(OBJ) $(F90) $(FFLAGS) -o $@ $(OBJ) clean: -rm $(OBJ) -rm $(DEST)/hello # extra dependencies sub2.o: modules.o

80 GNU make The material presented here assumes the use of GNU make (some parts may not work with other implementations of make) For more information see

81 sed + regular expressions Daniel Landau Martti Louhivuori

82 Regular expressions xkcd.com/208/

83 What are regular expressions? way of defining a common text pattern foo-[0-9] : foo-0, foo-1, foo-2,, foo-9 [Dd]og : Dog, dog X[a-z]*Z : XyZ, XabcZ, XZ, XfoZ, extremely useful and powerful tool

84 Regex syntax most characters are taken literally A matches A etc. some characters have special meaning. any character [] delimit a character class ^ beginning of a line $ end of a line OR (i.e. match cat or dog with cat dog) special characters can be made literal by escaping, e.g. \. matches a dot.

85 Regex syntax special shorthands available, too: \w [[:alnum:]] alphanumeric character \s [[:space:]] whitespace \d [[:digit:]] number [[:lower:]] lower case letter [[:upper:]] upper case letter wildcards: * 0 or more times + 1 or more times? 0 or 1 times {n} n times {n,m} at least n but no more than m times

86 Regex syntax character class defines all characters that will match [ab] a or b [A-Z] from A to Z, i.e. upper case letters [ab_-] a or B or _ or [0-9] any number [a-za-z] any letter [^x] anything else than x last word of warning: escaping varies between tools!

87 Regex exercises 1) two functions, a_function and b_function, are defined and used in file.c find the function declaration of a_function using grep the line should look something like 'int a_function( ) {' the function might be called many times, make sure you only find the declaration, not the places where it's called

88 Regex exercises the same problem, except this time you have to find the declaration of b_function 2) in the directory data/ s/ you will find some mega bytes of from the Linux kernel mailing list search for anything formatted like a US style address, i.e. '123 Fake street, New York City NY'

89 Regex resources ressions.html

90 sed sed has lots of commands, only one is discussed here: substitute sed -e 's/cat/dog/' animals.txt substitutes cat for dog once for each line in animals.txt and prints the result to standard output sed -e 's/cat/dog/g' animals.txt substitutes (globally) multiple occurences on the same line

91 sed refer to matching patterns: sed -e 's/\(\w\+\).c/\1.o/' Makefile \(PATTERN\) defines a PATTERN to match \1 refers to the first match sometimes syntax simplified by switching to extended regular expressions: sed -r -e 's/(\w+).c/\1.o/' Makefile

92 sed modify a file in-place: sed -i '.bak' -e 's/cat/dog/' animals.txt modifies animals.txt and copies the old contents to animals.txt.bak

93 sed resources everything: advanced things in blog form:

94 awk Daniel Landau Thomas Zwinger

95 awk Line based processing of column data with c-style programming constructs available Basic pattern: awk '/REGEX/ { commands }' file awk breaks the line into fields delimited by whitespace. Fields are available in variables from $1 onwards awk fields start with a $, but other variables don't

96 awk Special variables: NF contains the number of fields on the current line. NR contains the number of lines so far You can omit the regex, or even use any expression to decide which lines are processed, e.g. awk '{commands}' file for all lines awk 'NF == 5 {commands}' file for just the lines that have five fields awk '$1 == "yes" {commands}' file for lines where the first field is the string yes

97 awk Special words BEGIN and END awk 'BEGIN { begin_commands } { commands } END { end_commands }' The begin_commands are run before all lines and the end_commands after everything For example set sum = 0 at the beginning and print sum in the end

98 awk You can change the field delimiter with -F: awk -F ',' '{ commands }' file awk tutorial:

About This Course. Program, March 21 st. Practicalities. How We Teach. All topics are presented with interactive demonstrations.

About This Course. Program, March 21 st. Practicalities. How We Teach. All topics are presented with interactive demonstrations. Program, March 21 st About This Course 09:00 09:30 Morning coffee & registration 09:30 09:45 Introduction to the course and recap of previous courses 09:45 11:00 Bash scripting 11:00 12:00 Regular expressions

More information

Bourne Shell Reference

Bourne Shell Reference > Linux Reviews > Beginners: Learn Linux > Bourne Shell Reference Bourne Shell Reference found at Br. David Carlson, O.S.B. pages, cis.stvincent.edu/carlsond/cs330/unix/bshellref - Converted to txt2tags

More information

COMP 4/6262: Programming UNIX

COMP 4/6262: Programming UNIX COMP 4/6262: Programming UNIX Lecture 12 shells, shell programming: passing arguments, if, debug March 13, 2006 Outline shells shell programming passing arguments (KW Ch.7) exit status if (KW Ch.8) test

More information

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

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 Summer 2010 Department of Computer Science and Engineering York University Toronto June 29, 2010 1 / 36 Table of contents 1 2 3 4 2 / 36 Our goal Our goal is to see how we can use Unix as a tool for developing

More information

Basic Linux (Bash) Commands

Basic Linux (Bash) Commands Basic Linux (Bash) Commands Hint: Run commands in the emacs shell (emacs -nw, then M-x shell) instead of the terminal. It eases searching for and revising commands and navigating and copying-and-pasting

More information

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

EECS 470 Lab 5. Linux Shell Scripting. Friday, 1 st February, 2018 EECS 470 Lab 5 Linux Shell Scripting Department of Electrical Engineering and Computer Science College of Engineering University of Michigan Friday, 1 st February, 2018 (University of Michigan) Lab 5:

More information

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

Command Interpreters. command-line (e.g. Unix shell) On Unix/Linux, bash has become defacto standard shell. Command Interpreters A command interpreter is a program that executes other programs. Aim: allow users to execute the commands provided on a computer system. Command interpreters come in two flavours:

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

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

Introduction Variables Helper commands Control Flow Constructs Basic Plumbing. Bash Scripting. Alessandro Barenghi Bash Scripting Alessandro Barenghi Dipartimento di Elettronica, Informazione e Bioingegneria Politecnico di Milano alessandro.barenghi - at - polimi.it April 28, 2015 Introduction The bash command shell

More information

Useful Unix Commands Cheat Sheet

Useful Unix Commands Cheat Sheet Useful Unix Commands Cheat Sheet The Chinese University of Hong Kong SIGSC Training (Fall 2016) FILE AND DIRECTORY pwd Return path to current directory. ls List directories and files here. ls dir List

More information

Vi & Shell Scripting

Vi & Shell Scripting Vi & Shell Scripting Comp-206 : Introduction to Week 3 Joseph Vybihal Computer Science McGill University Announcements Sina Meraji's office hours Trottier 3rd floor open area Tuesday 1:30 2:30 PM Thursday

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

A shell can be used in one of two ways:

A shell can be used in one of two ways: Shell Scripting 1 A shell can be used in one of two ways: A command interpreter, used interactively A programming language, to write shell scripts (your own custom commands) 2 If we have a set of commands

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

We d like to hear your suggestions for improving our indexes. Send to

We d like to hear your suggestions for improving our indexes. Send  to Index [ ] (brackets) wildcard, 12 { } (curly braces) in variables, 41 ( ) (parentheses) in variables, 41 += (append) operator, 45 * (asterisk) wildcard, 12 $% automatic variable, 16 $+ automatic variable,

More information

Linux shell programming for Raspberry Pi Users - 2

Linux shell programming for Raspberry Pi Users - 2 Linux shell programming for Raspberry Pi Users - 2 Sarwan Singh Assistant Director(S) NIELIT Chandigarh 1 SarwanSingh.com Education is the kindling of a flame, not the filling of a vessel. - Socrates SHELL

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

Assignment clarifications

Assignment clarifications Assignment clarifications How many errors to print? at most 1 per token. Interpretation of white space in { } treat as a valid extension, involving white space characters. Assignment FAQs have been updated.

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

CSE 15L Winter Midterm :) Review

CSE 15L Winter Midterm :) Review 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

More information

Here redirection. Case statement. Advanced Unix Tools Lecture 6 CS214 Spring 2004 Friday March 5, 2004

Here redirection. Case statement. Advanced Unix Tools Lecture 6 CS214 Spring 2004 Friday March 5, 2004 Advanced Unix Tools Lecture 6 CS214 Spring 2004 Friday March, 2004 Here redirection Recall that redirection allows you to redirect the input to a command from a file (using

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

Bash scripting basics

Bash scripting basics Bash scripting basics prepared by Anatoliy Antonov for ESSReS community September 2012 1 Outline Definitions Foundations Flow control References and exercises 2 Definitions 3 Definitions Script - [small]

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

9.2 Linux Essentials Exam Objectives

9.2 Linux Essentials Exam Objectives 9.2 Linux Essentials Exam Objectives This chapter will cover the topics for the following Linux Essentials exam objectives: Topic 3: The Power of the Command Line (weight: 10) 3.3: Turning Commands into

More information

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

Answers to AWK problems. Shell-Programming. Future: Using loops to automate tasks. Download and Install: Python (Windows only.) R Today s Class Answers to AWK problems Shell-Programming Using loops to automate tasks Future: Download and Install: Python (Windows only.) R Awk basics From the command line: $ awk '$1>20' filename Command

More information

Lecture 5. Essential skills for bioinformatics: Unix/Linux

Lecture 5. Essential skills for bioinformatics: Unix/Linux Lecture 5 Essential skills for bioinformatics: Unix/Linux UNIX DATA TOOLS Text processing with awk We have illustrated two ways awk can come in handy: Filtering data using rules that can combine regular

More information

Last Time. on the website

Last Time. on the website Last Time on the website Lecture 6 Shell Scripting What is a shell? The user interface to the operating system Functionality: Execute other programs Manage files Manage processes Full programming language

More information

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

Shell Scripting. With Applications to HPC. Edmund Sumbar Copyright 2007 University of Alberta. All rights reserved AICT High Performance Computing Workshop With Applications to HPC Edmund Sumbar research.support@ualberta.ca Copyright 2007 University of Alberta. All rights reserved High performance computing environment

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

EECS2301. Special variables. $* and 3/14/2017. Linux/Unix part 2

EECS2301. Special variables. $* and 3/14/2017. Linux/Unix part 2 Warning: These notes are not complete, it is a Skelton that will be modified/add-to in the class. If you want to us them for studying, either attend the class or get the completed notes from someone who

More information

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1 Shell Scripting Todd Kelley kelleyt@algonquincollege.com CST8207 Todd Kelley 1 If we have a set of commands that we want to run on a regular basis, we could write a script A script acts as a Linux command,

More information

1. Hello World Bash Shell Script. Last Updated on Wednesday, 13 April :03

1. Hello World Bash Shell Script. Last Updated on Wednesday, 13 April :03 1 of 18 21/10/2554 9:39 Bash scripting Tutorial tar -czf myhome_directory.tar.gz /home/linuxcong Last Updated on Wednesday, 13 April 2011 08:03 Article Index 1. Hello World Bash Shell Script 2. Simple

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

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

CS 25200: Systems Programming. Lecture 10: Shell Scripting in Bash CS 25200: Systems Programming Lecture 10: Shell Scripting in Bash Dr. Jef Turkstra 2018 Dr. Jeffrey A. Turkstra 1 Lecture 10 Getting started with Bash Data types Reading and writing Control loops Decision

More information

Cisco IOS Shell. Finding Feature Information. Prerequisites for Cisco IOS.sh. Last Updated: December 14, 2012

Cisco IOS Shell. Finding Feature Information. Prerequisites for Cisco IOS.sh. Last Updated: December 14, 2012 Cisco IOS Shell Last Updated: December 14, 2012 The Cisco IOS Shell (IOS.sh) feature provides shell scripting capability to the Cisco IOS command-lineinterface (CLI) environment. Cisco IOS.sh enhances

More information

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

Shell. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong Shell Prof. Jinkyu Jeong (Jinkyu@skku.edu) TA -- Minwoo Ahn (minwoo.ahn@csl.skku.edu) TA -- Donghyun Kim (donghyun.kim@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu

More information

UNIX System Programming Lecture 3: BASH Programming

UNIX System Programming Lecture 3: BASH Programming UNIX System Programming Outline Filesystems Redirection Shell Programming Reference BLP: Chapter 2 BFAQ: Bash FAQ BMAN: Bash man page BPRI: Bash Programming Introduction BABS: Advanced Bash Scripting Guide

More information

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

COMP 2718: Shell Scripts: Part 1. By: Dr. Andrew Vardy COMP 2718: Shell Scripts: Part 1 By: Dr. Andrew Vardy Outline Shell Scripts: Part 1 Hello World Shebang! Example Project Introducing Variables Variable Names Variable Facts Arguments Exit Status Branching:

More information

Basic Shell Scripting

Basic Shell Scripting Basic Shell Scripting Wei Feinstein HPC User Services LSU HPC & LON sys-help@loni.org February 2018 Outline Introduction to Linux Shell Shell Scripting Basics Variables Quotations Beyond Basic Shell Scripting

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

GNU make... Martin Ohlerich, Parallel Programming of High Performance Systems

GNU make... Martin Ohlerich, Parallel Programming of High Performance Systems ... Martin Ohlerich, Martin.Ohlerich@lrz.de Parallel Programming of High Performance Systems Outline 1 2 3 Leibniz Rechenzentrum 2 / 42 Outline 1 2 3 Leibniz Rechenzentrum 3 / 42 Common Situation Larger

More information

bash Args, Signals, Functions Administrative Shell Scripting COMP2101 Fall 2017

bash Args, Signals, Functions Administrative Shell Scripting COMP2101 Fall 2017 bash Args, Signals, Functions Administrative Shell Scripting COMP2101 Fall 2017 Positional Arguments It is quite common to allow the user of a script to specify what the script is to operate on (e.g. a

More information

Introduction to the Shell

Introduction to the Shell [Software Development] Introduction to the Shell Davide Balzarotti Eurecom Sophia Antipolis, France What a Linux Desktop Installation looks like What you need Few Words about the Graphic Interface Unlike

More information

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

Introduction to Linux Basics Part II. Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala Introduction to Linux Basics Part II 1 Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala pakala@uga.edu 2 Variables in Shell HOW DOES LINUX WORK? Shell Arithmetic I/O and

More information

Shell programming. Introduction to Operating Systems

Shell programming. Introduction to Operating Systems Shell programming Introduction to Operating Systems Environment variables Predened variables $* all parameters $# number of parameters $? result of last command $$ process identier $i parameter number

More information

[Software Development] Makefiles. Davide Balzarotti. Eurecom Sophia Antipolis, France

[Software Development] Makefiles. Davide Balzarotti. Eurecom Sophia Antipolis, France [Software Development] Makefiles Davide Balzarotti Eurecom Sophia Antipolis, France 1 Software Development Tools 1. Configuring and Building the program GCC Makefiles Autotools 2. Writing and managing

More information

INTRODUCTION TO SHELL SCRIPTING ITPART 2

INTRODUCTION TO SHELL SCRIPTING ITPART 2 INTRODUCTION TO SHELL SCRIPTING ITPART 2 Dr. Jeffrey Frey University of Delaware, version 2 GOALS PART 2 Shell plumbing review Standard files Redirection Pipes GOALS PART 2 Command substitution backticks

More information

Title:[ Variables Comparison Operators If Else Statements ]

Title:[ Variables Comparison Operators If Else Statements ] [Color Codes] Environmental Variables: PATH What is path? PATH=$PATH:/MyFolder/YourStuff?Scripts ENV HOME PWD SHELL PS1 EDITOR Showing default text editor #!/bin/bash a=375 hello=$a #No space permitted

More information

Bashed One Too Many Times. Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009

Bashed One Too Many Times. Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009 Bashed One Too Many Times Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009 What is a Shell? The shell interprets commands and executes them It provides you with an environment

More information

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

CSCI 211 UNIX Lab. Shell Programming. Dr. Jiang Li. Jiang Li, Ph.D. Department of Computer Science CSCI 211 UNIX Lab Shell Programming Dr. Jiang Li Why Shell Scripting Saves a lot of typing A shell script can run many commands at once A shell script can repeatedly run commands Help avoid mistakes Once

More information

Lab 4: Shell scripting

Lab 4: Shell scripting Lab 4: Shell scripting Comp Sci 1585 Data Structures Lab: Tools Computer Scientists Outline 1 2 3 4 5 6 What is shell scripting good? are the duct tape and bailing wire of computer programming. You can

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

Computer Systems and Architecture

Computer Systems and Architecture Computer Systems and Architecture Stephen Pauwels UNIX Scripting Academic Year 2018-2019 Outline Basics Conditionals Loops Advanced Exercises Shell Scripts Grouping commands into a single file Reusability

More information

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

Windshield. Language Reference Manual. Columbia University COMS W4115 Programming Languages and Translators Spring Prof. Stephen A. Windshield Language Reference Manual Columbia University COMS W4115 Programming Languages and Translators Spring 2007 Prof. Stephen A. Edwards Team members Wei-Yun Ma wm2174 wm2174@columbia.edu Tony Wang

More information

5/20/2007. Touring Essential Programs

5/20/2007. Touring Essential Programs Touring Essential Programs Employing fundamental utilities. Managing input and output. Using special characters in the command-line. Managing user environment. Surveying elements of a functioning system.

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

CSCI 2132: Software Development

CSCI 2132: Software Development CSCI 2132: Software Development Lab 4/5: Shell Scripting Synopsis In this lab, you will: Learn to work with command-line arguments in shell scripts Learn to capture command output in variables Learn to

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

Shell Start-up and Configuration Files

Shell Start-up and Configuration Files ULI101 Week 10 Lesson Overview Shell Start-up and Configuration Files Shell History Alias Statement Shell Variables Introduction to Shell Scripting Positional Parameters echo and read Commands if and test

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

Linux Bash Shell Scripting

Linux Bash Shell Scripting University of Chicago Initiative in Biomedical Informatics Computation Institute Linux Bash Shell Scripting Present by: Mohammad Reza Gerami gerami@ipm.ir Day 2 Outline Support Review of Day 1 exercise

More information

UNIX shell scripting

UNIX shell scripting UNIX shell scripting EECS 2031 Summer 2014 Przemyslaw Pawluk June 17, 2014 What we will discuss today Introduction Control Structures User Input Homework Table of Contents Introduction Control Structures

More information

Shell Script Example. Here is a hello world shell script: $ ls -l -rwxr-xr-x 1 horner 48 Feb 19 11:50 hello* $ cat hello #!/bin/sh

Shell Script Example. Here is a hello world shell script: $ ls -l -rwxr-xr-x 1 horner 48 Feb 19 11:50 hello* $ cat hello #!/bin/sh Shell Programming Shells A shell can be used in one of two ways: A command interpreter, used interactively A programming language, to write shell scripts (your own custom commands) Shell Scripts A shell

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

Basics. I think that the later is better.

Basics.  I think that the later is better. Basics Before we take up shell scripting, let s review some of the basic features and syntax of the shell, specifically the major shells in the sh lineage. Command Editing If you like vi, put your shell

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

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

Computer Systems and Architecture

Computer Systems and Architecture Computer Systems and Architecture UNIX Scripting Bart Meyers University of Antwerp August 29, 2012 Outline Basics Conditionals Loops Advanced Exercises Shell scripts Grouping commands into a single file

More information

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?

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? Today Unix as an OS case study Intro to Shell Scripting Make sure the computer is in Linux If not, restart, holding down ALT key Login! Posted slides contain material not explicitly covered in class 1

More information

Grep and Shell Programming

Grep and Shell Programming Grep and Shell Programming Comp-206 : Introduction to Software Systems Lecture 7 Alexandre Denault Computer Science McGill University Fall 2006 Teacher's Assistants Michael Hawker Monday, 14h30 to 16h30

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

UNIX II:grep, awk, sed. October 30, 2017

UNIX II:grep, awk, sed. October 30, 2017 UNIX II:grep, awk, sed October 30, 2017 File searching and manipulation In many cases, you might have a file in which you need to find specific entries (want to find each case of NaN in your datafile for

More information

EECS2301. Example. Testing 3/22/2017. Linux/Unix Part 3. for SCRIPT in /path/to/scripts/dir/* do if [ -f $SCRIPT -a -x $SCRIPT ] then $SCRIPT fi done

EECS2301. Example. Testing 3/22/2017. Linux/Unix Part 3. for SCRIPT in /path/to/scripts/dir/* do if [ -f $SCRIPT -a -x $SCRIPT ] then $SCRIPT fi done Warning: These notes are not complete, it is a Skelton that will be modified/add-to in the class. If you want to us them for studying, either attend the class or get the completed notes from someone who

More information

Mills HPC Tutorial Series. Linux Basics II

Mills HPC Tutorial Series. Linux Basics II Mills HPC Tutorial Series Linux Basics II Objectives Bash Shell Script Basics Script Project This project is based on using the Gnuplot program which reads a command file, a data file and writes an image

More information

Essentials for Scientific Computing: Bash Shell Scripting Day 3

Essentials for Scientific Computing: Bash Shell Scripting Day 3 Essentials for Scientific Computing: Bash Shell Scripting Day 3 Ershaad Ahamed TUE-CMS, JNCASR May 2012 1 Introduction In the previous sessions, you have been using basic commands in the shell. The bash

More information

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

Linux Systems Administration Shell Scripting Basics. Mike Jager Network Startup Resource Center Linux Systems Administration Shell Scripting Basics Mike Jager Network Startup Resource Center mike.jager@synack.co.nz These materials are licensed under the Creative Commons Attribution-NonCommercial

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

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

Unix Shell scripting. Dr Alun Moon 7th October Introduction. Notation. Spaces Unix Shell scripting Dr Alun Moon 7th October 2017 Introduction Shell scripts in Unix are a very powerfull tool, they form much of the standard system as installed. What are these good for? So many file

More information

Introduction to UNIX Part II

Introduction to UNIX Part II T H E U N I V E R S I T Y of T E X A S H E A L T H S C I E N C E C E N T E R A T H O U S T O N S C H O O L of H E A L T H I N F O R M A T I O N S C I E N C E S Introduction to UNIX Part II For students

More information

Welcome to the Bash Workshop!

Welcome to the Bash Workshop! Welcome to the Bash Workshop! If you prefer to work on your own, already know programming or are confident in your abilities, please sit in the back. If you prefer guided exercises, are completely new

More information

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines. Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

Shell Scripting. Xiaoxu Guan High Performance Computing, LSU February 17, 2016

Shell Scripting. Xiaoxu Guan High Performance Computing, LSU February 17, 2016 Shell Scripting Xiaoxu Guan High Performance Computing, LSU February 17, 2016 #!/bin/bash (? ) (?=[a-za-z]) LSU HPC Training Series, Spring 2016 p. 1/46 Overview What is a shell? LSU HPC Training

More information

bash Execution Control COMP2101 Winter 2019

bash Execution Control COMP2101 Winter 2019 bash Execution Control COMP2101 Winter 2019 Bash Execution Control Scripts commonly can evaluate situations and make simple decisions about actions to take Simple evaluations and actions can be accomplished

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

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 CSC209 Review CSC209: Software tools Unix files and directories permissions utilities/commands Shell programming quoting wild cards files ... and systems programming C basic syntax functions arrays structs

More information

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

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs. CSC209 Review CSC209: Software tools Unix files and directories permissions utilities/commands Shell programming quoting wild cards files... and systems programming C basic syntax functions arrays structs

More information

Automating Tasks Using bash

Automating Tasks Using bash Overview Automating Tasks Using bash SHARCNET Introduction to command shells & bash bash fundamentals I/O redirection, pipelining, wildcard expansion, shell variables Shell scripting writing bash scripts

More information

Basic Shell Scripting Practice. HPC User Services LSU HPC & LON March 2018

Basic Shell Scripting Practice. HPC User Services LSU HPC & LON March 2018 Basic Shell Scripting Practice HPC User Services LSU HPC & LON sys-help@loni.org March 2018 Quotation Exercise 1. Print out your $LOGNAME 2. Print date 3. Print `who am i` 4. Print your current directory

More information

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

LING 408/508: Computational Techniques for Linguists. Lecture 5 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

More information

Bash Shell Programming Helps

Bash Shell Programming Helps Bash Shell Programming Helps We use the Bash shell to orchestrate the chip building process Bash shell calls the other tools, does vector checking The shell script is a series of commands that the Bash

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

Makefile Brief Reference

Makefile Brief Reference Makefile Brief Reference COMP 229, 346, 444, 5201 Revision 1.1 Date: July 31, 2003 1 Contents Intro Format Examples 2 Intro Makefiles in conjunction with the make utility (man make) provide a very convenient

More information

GNU Bash. an introduction to advanced usage. James Pannacciulli Systems Engineer.

GNU Bash. an introduction to advanced usage. James Pannacciulli Systems Engineer. Concise! GNU Bash http://talk.jpnc.info/bash_lfnw_2017.pdf an introduction to advanced usage James Pannacciulli Systems Engineer Notes about the presentation: This talk assumes you are familiar with basic

More information

CSC209 Review. Yeah! We made it!

CSC209 Review. Yeah! We made it! CSC209 Review Yeah! We made it! 1 CSC209: Software tools Unix files and directories permissions utilities/commands Shell programming quoting wild cards files 2 ... and C programming... C basic syntax functions

More information

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

OPERATING SYSTEMS LAB LAB # 6. I/O Redirection and Shell Programming. Shell Programming( I/O Redirection and if-else Statement) P a g e 1 OPERATING SYSTEMS LAB LAB 6 I/O Redirection and Shell Programming Lab 6 Shell Programming( I/O Redirection and if-else Statement) P a g e 2 Redirection of Standard output/input i.e. Input - Output

More information

Shell Programming Overview

Shell Programming Overview Overview Shell programming is a way of taking several command line instructions that you would use in a Unix command prompt and incorporating them into one program. There are many versions of Unix. Some

More information

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

28-Nov CSCI 2132 Software Development Lecture 33: Shell Scripting. 26 Shell Scripting. Faculty of Computer Science, Dalhousie University Lecture 33 p.1 Faculty of Computer Science, Dalhousie University CSCI 2132 Software Development Lecture 33: Shell Scripting 28-Nov-2018 Location: Chemistry 125 Time: 12:35 13:25 Instructor: Vla Keselj

More information

STATS Data Analysis using Python. Lecture 15: Advanced Command Line

STATS Data Analysis using Python. Lecture 15: Advanced Command Line STATS 700-002 Data Analysis using Python Lecture 15: Advanced Command Line Why UNIX/Linux? As a data scientist, you will spend most of your time dealing with data Data sets never arrive ready to analyze

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