Sunteți pe pagina 1din 38

Unix C + GNU HTML Perl Python

Vi! Shell Memory " #rep


Comp-206 $ %&tro'(ctio& to Software Systems )ee* +ay 1 Joseph Vybihal Comp(ter Scie&ce Mc#ill ,&i-ersity
Vybihal (c) 201

COMP 206 - Joseph Vybihal Software Systems

Unix C + GNU HTML Perl Python

.t /ome
0 1ash a&' comma&'-li&e help$
2 http$33ss645com3bash3

0 6e7(lar 89pressio&s
2 http$33e&5wi*ipe'ia5or73wi*i36e7(lar:e9pressio&:e9amples 2 http$33www5;ytra95com3tech3web3re7e95htm

0 Practice writi&7 re7(lar e9pressio&s


2 <o( ca& (se 7rep to help yo( 'o his

COMP 206 - Joseph Vybihal Software Systems

Vybihal (c) 201

Unix C + GNU HTML Perl Python

.&&o(&ceme&ts

=.>s

COMP 206 - Joseph Vybihal Software Systems

Vybihal (c) 201

Unix C + GNU HTML Perl Python

Part 1
,&i9 8'itors
COMP 206 - Joseph Vybihal Software Systems

Vybihal (c) 201

Unix C + GNU HTML Perl Python

8'itor
0 Comma&' li&e te9t e'itors allow yo( to create3e'it files at the comma&' li&e5 Se-eral te9t e'itors are a-ailable5
vi is o&e of the ori7i&al te9t e'itor a-ailable o& ,&i95 %t>s -ery 'iffic(lt to (se a&' lear&5 /owe-er! its -ery powerf(l a&' a-ailable o& e-ery ,&i9 machi&es5 pico is a simple te9t e'itor base' o& the pine mail clie&t5 %t>s -ery easy to (se! a&' is a-ailable o& most ,&i9 machi&es5 emacs is a -ery pop(lar a&' powerf(l5 Co&si'eri&7 the &(mber of feat(res it has! it sho(l' be co&si'ere' a hea-y wei7ht clie&t5

COMP 206 - Joseph Vybihal Software Systems

0 <o( ca& also (se 7raphical te9t e'itors! s(ch as bl(efish! 7e'it or @e'it5 0 .s a lo&7 term i&-estme&t! % hi7hly s(77est yo( lear& vi5
Vybihal (c) 201

Unix C + GNU HTML Perl Python

89ample of =e9t 8'itors


=e9t base'! co&sole 0 0 0 0 0 0 Vi 8macs Pico 8' JStar 3 Jo-e 8'it ('os) #raphic base'! #,% 0 0 0 0 0 0 Aemacs 1l(efish #e'it (#&ome) Bate (B+8) Je'it (@a-a) Cotepa' (wi&'ows)
6

COMP 206 - Joseph Vybihal Software Systems

Vybihal (c) 201

Unix C + GNU HTML Perl Python

Part 2
=he Vi 8'itor
COMP 206 - Joseph Vybihal Software Systems

Vybihal (c) 201

Unix C + GNU HTML Perl Python

ViFs Mo'es
0 Si&ce &o me&( system! it (ses mo'es
2 %&sert Mo'e$ (8SC i)
0 to e'it yo(r te9t 0 ca& press a&y *eyboar' characters 0 some -iFs let yo( (se arrow *ey

2 8scape Mo'e$
COMP 206 - Joseph Vybihal Software Systems

(press 8SC)

0 termi&ates e'it 0 ca& (se arrow *eys 0 ca& (se special o&e letter comma&'

2 Comma&' Mo'e$
Vybihal (c) 201

(8SC $)
E

0 iss(e comma&'s li*e Sa-e! Goa'! a&' H(ite

Unix C + GNU HTML Perl Python

Vi Mo'e Beys
0 Comma&' Mo'e
2 Press the $ *ey 2 .ss(mes yo( are i& escape mo'e

0 8'it Mo'e
2 Ma&y *eys 7et yo( i&to this mo'e$ i! a! o! O 2 .ss(mes yo( are i& escape mo'e
COMP 206 - Joseph Vybihal Software Systems

0 8scape Mo'e
2 Press the 8SC *ey 2 6et(r&s yo( to 8scape mo'e
Vybihal (c) 201

Unix C + GNU HTML Perl Python

. sample Vi sessio&555

COMP 206 - Joseph Vybihal Software Systems

Vybihal (c) 201

10

Unix C + GNU HTML Perl Python

%mporta&t Comma&'s

%&serti&7

.&y of the followi&7$ i! a! o! O =o 'elete$ ''! 9 =o search$ 3 w! J! wJ! JK! li&e &(mber! e file&ame

%& 8SC mo'e


COMP 206 - Joseph Vybihal Software Systems

Comma&' mo'e

Vybihal (c) 201

11

Unix C + GNU HTML Perl Python

COMP 206 - Joseph Vybihal Software Systems

Vybihal (c) 201

12

Unix C + GNU HTML Perl Python

COMP 206 - Joseph Vybihal Software Systems

Vybihal (c) 201

Unix C + GNU HTML Perl Python

Part
6e7(lar 89pressio&s a&' comma&'s that (se it
COMP 206 - Joseph Vybihal Software Systems

Vybihal (c) 201

14

Unix C + GNU HTML Perl Python

6e7(lar 89pressio&s
0 Se-eral ,&i9 comma&'s a&' e'itors allow yo( to search o& te9t patter&s5 0 =hese te9t patter&s are *&ow& as re7(lar e9pressio&s (re7e9)5

COMP 206 - Joseph Vybihal Software Systems

Vybihal (c) 201

1?

Unix C + GNU HTML Perl Python

7rep! se' a&' aw*


0 7rep Loptio&sM stri&7 files
2 search for occ(rre&ces of the stri&75

0 se' Loptio&sM files


2 stream e'itor for e'iti&7 files5
COMP 206 - Joseph Vybihal Software Systems

0 aw* Loptio&sM files


2 sca& for patter&s i& a file a&' process the res(lts5 (script e9ec(tio&)
Perl a&' Pytho& as well5 Vybihal (c) 201
16

Unix C + GNU HTML Perl Python

#rep
grep is (se' to search for the occ(rre&ce of a re7(lar e9pressio& i& files5 0 6e7(lar e9pressio&s! are best specifie' i& apostrophes (or si&7le J(otes) whe& (se' with 7rep5 0 Some commo& optio&s i&cl('e$
2 2 2 2 -i $ i7&ore case -c $ report o&ly a co(&t of the &(mber of li&es co&tai&i&7 matches -- $ i&-ert the search! 'isplayi&7 o&ly li&es that 'o &ot match -& $ 'isplay the li&e &(mber alo&7 with the li&e o& which a match was fo(&' 2 -l $ list file&ames! b(t &ot li&es! i& which matches were fo(&'

COMP 206 - Joseph Vybihal Software Systems

Vybihal (c) 201

1D

Unix C + GNU HTML Perl Python

89amples of 7rep
0 Co&si'er the followi&7 te9t file $
Alex Marc Micheal Ting Juan Jeremy Jessica Yannick Nicolas Jean-Sebastien Na eem
Vybihal (c) 201

COMP 206 - Joseph Vybihal Software Systems

1E

Unix C + GNU HTML Perl Python

89amples of 7rep (co&t5)


0 #rep for a specific stri&7 5 5 5
!"vybihal#!$%cs&'(# grep )Je) Jeremy Jessica Jean-Sebastien emo*txt

!"vybihal#!$%cs&'(# grep -n )Je) (+Jeremy ,+Jessica -'+Jean-Sebastien !"vybihal#!$%cs&'(# grep -c )Je) .


Vybihal (c) 201

emo*txt

COMP 206 - Joseph Vybihal Software Systems

emo*txt

1I

Unix C + GNU HTML Perl Python !"vybihal#!$%cs&'(# grep -i )/!aeiouy#)

89amples of 7rep (co&t5)


emo*txt

0 #rep for -owels 5 5 5


Alex Yannick

!"vybihal#!$%cs&'(# grep -i )!aeiouy#0)

emo*txt

Jeremy Jessica
COMP 206 - Joseph Vybihal Software Systems

!"vybihal#!$%cs&'(# grep -i )!aeiouy#1&23)

emo*txt

Micheal Juan Yannick Jean-Sebastien Na eem


Vybihal (c) 201

20

Unix C + GNU HTML Perl Python

89amples of 7rep (co&t5)


0 #rep for specific characters 5 5 5
!"vybihal#!$%cs&'(# grep -i )/*e) Jeremy Jessica Jean-Sebastien
!"vybihal#!$%cs&'(# grep -i )/*e4a*0)

emo*txt

emo*txt

Micheal Juan Jeremy Jessica Nicolas Jean-Sebastien


Vybihal (c) 201

COMP 206 - Joseph Vybihal Software Systems

21

Unix C + GNU HTML Perl Python

6e7e9 Sy&ta9
0 =a*e a loo* at the 6e7e9 Sy&ta9 J(ic* sheet5
2 Giteral characters are combi&atio& to represe&t special characters5 2 Character classes are combi&atio& to represe&t 7ro(ps of characters5 2 6epetitio& i&'icate how ofte& a character sho(l' be appear to be a match5 2 .&chors 'etermi&e where the matchi&7 stri&7 m(st be fo(&'5
Vybihal (c) 201

COMP 206 - Joseph Vybihal Software Systems

22

Unix C + GNU HTML Perl Python

COMP 206 - Joseph Vybihal Software Systems

Vybihal (c) 201

Unix C + GNU HTML Perl Python

)he& to (se 7rep


0 #rep is a (sef(l tool to fi&' specific stri&7s5
2 O(tli&i&7 all the errors i& a lo7 file5 2 Ni&'i&7 a specific stri&7 i& a collectio& of so(rce files5

0 %t becomes a& e-e& more powerf(l tool whe& combi&e' with other (tilities5
COMP 206 - Joseph Vybihal Software Systems

!"vybihal#!$%cs&'(# ps -e 4 grep )"ava) -5&6( pts%- ''+-7+.' "ava &-.86 9 ''+''+'7 "ava --&-7 pts%5 ''+'.+6- "ava
Vybihal (c) 201

24

Unix C + GNU HTML Perl Python

Part 4
=he Shell 8&-iro&me&t Memory
COMP 206 - Joseph Vybihal Software Systems

Vybihal (c) 201

2?

Unix C + GNU HTML Perl Python

8&-iro&me&t 89ample
:;<NAM=>"vybihal ?;M=>%home%user%"vybihal @AT?>%bin+%usr%bin+%usr%local%bin MAA:>%var%mail%"vybihal S?=::>tcsh SS?BC;NN=CTA;N>-.&*&'(*6-*&&( &555 -.&*&'(*.*-5& && SS?BTTY>% ev%pts%( T=DM>xterm ?;STTY@=>i.7(-linux E=NF;D>intel ;STY@=>linux MAC?TY@=>i.7( S?:E:>@GF>%home%user%"vybihal <D;H@>unknoIn
Vybihal (c) 201

COMP 206 - Joseph Vybihal Software Systems

26

Unix C + GNU HTML Perl Python

8&-iro&me&t Memory
0 )he& a shell is starte'! the OS sets (p a& e&-iro&me&t for that shell5 0 =his e&-iro&me&t ca& be 'escribe' by a collectio& of -ariables (e&-iro&me&t -ariables)5
2 =hese -ariables are accessible to a&y applicatio& la(&che' from that e&-iro&me&t

0 =he env or set comma&' is (se' to 'isplay the c(rre&t e&-iro&me&t -ariables5 0 =he setenv or set comma&' allows yo( to cha&7e a& e&-iro&me&t -ariable5 0 =he echo comma&' ca& be (se to pri&t o(t i&'i-i'(al e&-iro&me&t -ariables5
echo 0;S
Vybihal (c) 201

COMP 206 - Joseph Vybihal Software Systems

Or$ S8=
2D

Unix C + GNU HTML Perl Python

,si&7 the 8&-iro&me&t


0 set
2 +isplay co&te&ts of shell memory

0 set V.6OV.G
2 Create a &ew -ariable with a -al(e

0 set V.6O
2 +eletes a -ariable a&' -al(e
COMP 206 - Joseph Vybihal Software Systems

0 echo PV.6
2 +isplays the -al(e

.lter&ates$ sete&- V.6 V.G e&-

We will talk about this more when we program the Shell.


Vybihal (c) 201

2E

Unix C + GNU HTML Perl Python

. sample S8= sessio&

COMP 206 - Joseph Vybihal Software Systems

Vybihal (c) 201

2I

Unix C + GNU HTML Perl Python

Part ?
%&tro'(ctio& to Scripts
COMP 206 - Joseph Vybihal Software Systems

Vybihal (c) 201

Unix C + GNU HTML Perl Python

=wo *i&'s of scripts


0 1oot a&' Go7i& scripts
2 2 2 ,se' to mo'ify the OS e&-iro&me&t 1oot scripts are create' by s(per (ser for all Go7i& scripts create' by ow&er for him3herself Create' by (sers to a(tomate comma&'li&e acti-ities
Vybihal (c) 201

COMP 206 - Joseph Vybihal Software Systems

Comma&'-li&e scripts
2

Unix C + GNU HTML Perl Python

=he .rchitect(re
=he /ar'ware =he OS =he Shell

COMP 206 - Joseph Vybihal Software Systems

=he Comma&'-li&e
. wi&'ow is a special case of this

=he Script

<O,
Vybihal (c) 201

Unix C + GNU HTML Perl Python

Script (1atch)
0 Scripts are collectio&s of comma&'s! 7ro(pe' i& a file a&' seJ(e&tially e9ec(te5 0 Scripts are &ot compile' pro7rams! they are i&terprete'5 0 Scripts r(& from top to bottom! with little co&trol flow ('oes &ot ha-e the comple9ity of a piece of software)5 0 System a'mi&istrators (se script to a(tomate comple9 tas*s5
2 1e s(re to C/MO+ it to e9ec(teK
Vybihal (c) 201

COMP 206 - Joseph Vybihal Software Systems

Unix C + GNU HTML Perl Python

89ample script
clear who fi&7er bob ie o(tloo* J(oteofthe'ay
chmo' R9 file

COMP 206 - Joseph Vybihal Software Systems

Vybihal (c) 201

=as*s at lo7i&Q5

Unix C + GNU HTML Perl Python

1ash
0 1.S/ is a ,&i9 scripti&7 la&7(a7e that impleme&ts some pro7rammi&7 la&7(a7e co&trol flows! li*e$
2 2 2 2 7oto if for while

COMP 206 - Joseph Vybihal Software Systems

0 1(t it is a script! it is i&terprete' by the OS! &ot compile' a&' e9ec(te' by the CP,5
Vybihal (c) 201

Unix C + GNU HTML Perl Python

,ses of script files


0 1ac*(p scripts
2 archi-i&7 importa&t files a&' sa-i&7 them i& a safe place5

0 Start(p scripts
2 applicatio& which reJ(ire a complicate' e&-iro&me&t to r(&5 2 pro7rams yo( ofte& r(& whe& yo(r sessio& be7i&s

0 Sche'(le' scripts
2 re7(larly rotati&7 a&' archi-i&7 lo7s5
COMP 206 - Joseph Vybihal Software Systems

0 Mai&te&a&ce scripts
2 a script that creates a (ser or cha&7es a passwor' o& m(ltiple system! all i& o&e comma&'5

0 Pro7rammer scripts
2 compili&7! -ersio& co&trol a&' bac*(ps i& o&e step Vybihal (c) 201
6

Unix C + GNU HTML Perl Python

+efa(lt 1ash Niles


0 0 0 0 5cshrc 5*shrc 5lo7i& 5bash:profile csh lo7i& script *sh lo7i& script sh lo7i& script bash lo7i& script e9tra fi&7er i&fo email forwar'i&7 sh a&' csh lo7o(t

COMP 206 - Joseph Vybihal Software Systems

0 5pla& 0 5forwar' 0 5lo7o(t

Vybihal (c) 201

Unix C + GNU HTML Perl Python

CoteK
Go7i& scripts o&ly r(& whe& yo( lo7i&! &ot from the comma&'-li&e prompt5 Go7i& scripts reJ(ire yo( to (se sete&- whe& cha&7i&7 the r(&-time e&-iro&me&t5

COMP 206 - Joseph Vybihal Software Systems

Vybihal (c) 201

S-ar putea să vă placă și