Documente Academic
Documente Profesional
Documente Cultură
.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
.&&o(&ceme&ts
=.>s
Part 1
,&i9 8'itors
COMP 206 - Joseph Vybihal Software Systems
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
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
Part 2
=he Vi 8'itor
COMP 206 - Joseph Vybihal Software Systems
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
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
. sample Vi sessio&555
10
%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
Comma&' mo'e
11
12
Part
6e7(lar 89pressio&s a&' comma&'s that (se it
COMP 206 - Joseph Vybihal Software Systems
14
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
1?
#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(&'
1D
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
1E
emo*txt
emo*txt
1I
emo*txt
Jeremy Jessica
COMP 206 - Joseph Vybihal Software Systems
emo*txt
20
emo*txt
emo*txt
21
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
22
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
Part 4
=he Shell 8&-iro&me&t Memory
COMP 206 - Joseph Vybihal Software Systems
2?
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
26
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
Or$ S8=
2D
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
2E
2I
Part ?
%&tro'(ctio& to Scripts
COMP 206 - Joseph Vybihal Software Systems
Comma&'-li&e scripts
2
=he .rchitect(re
=he /ar'ware =he OS =he Shell
=he Comma&'-li&e
. wi&'ow is a special case of this
=he Script
<O,
Vybihal (c) 201
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
89ample script
clear who fi&7er bob ie o(tloo* J(oteofthe'ay
chmo' R9 file
=as*s at lo7i&Q5
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
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
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
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