Shell trong Linux.
SHELL---_LINUX !"#$%&'(")*+&,-.%/&,-011/&2+&34&'& !/&/&5/&3"4-6788&!"9:55! 788-;&<)--!= 8>--!=7%? ' 8>7%?<@A-B#C&DE%!"! "F8"%788 #"$ $>GH)7-!!87I@AJK"%L"$;)M@A$N#O+! $M@PQ!RPQ!$34&'&/$S'PT6G(")@P*$788HI F/U@D"N#O+V"WHXIH I LB@A#U;!""N#''P$H2I $&W>Y!YMHZI #!'-6$'P[\KK!"!?SV!?S]]H1I LB^_`@@V/$# $%&R")%"'P$_4&'&!",/X$S?7,' ()a@Pbc_'P$=34&'&7d&ed"f_$=e3'&g#B#O+%"Gbg7&h&"Y#O+7!""i"fi!!87H$"BIi!#&!7i#B%"Gbi%"Gbi*@D"bi!ii"i7j7k-6!!i!iiGi]SHELL_LINUX 1-18 1 SHELL---_LINUX* +,-./012 34056̉ ̣ 34&'&7%&&&h&'& 7%&.27%& j7%&?5 7%& ?l27%&?i`27m7%&n.2moSm7&%,o.2m./012 3407580̉ ̣pqrstruŕ ̣87koS,o.2]87ko.S2]87koS,-`,]./012 3409::;;;<<̉ ̣vqrstrú ̣oS,HHo.2IIoS,HH,-`,II 7&% ?l2 ?-27&%?i`2&h&'W_+i`#B&`@&W>#O+!)$ab"G/@Aw*"788_#-68>@A@VY! "mmH#B&"')@xyI788<+8>@!Sm7&%?i`2m!<'P8;?%2S2?#$("!-;7,!= >?@A@BCDEFG328"!"a" F/ zQ!k [')#h& N-)')#h&@A%7-8;Y#O+/>x [')@ YN-"')@OQ!#B@{m [')A +8>7kB-!)8;!7]#B@AB-!)8;-)7kB-!)8;m!7m]<!;)'B-!)!7N-"')AmmH +I-JK>V@PK"%_#-68>V&+_* 8|'P@%'@P%7-8>V&@+;B#BHI[$"'P*8;?Ho7I8>+;BH I[$"'P*#'?Ho7I#B;B}'P@~|8;E%!"•)8;-$;@$@A'P*€!-68>!)&^•@_‚Dw$@V>ƒ€!788L$"%'„87#B…|/@Q!9-"#†„8797,^<!-;-6'P#'?M ()NOP-QRS&,TUVa@8)Y8>"•&‡;&-;8";$SHELL_LINUX 2-18 2 SHELL---_LINUX34&'&7!!! !2=![7!#B!-G'P<@A!$,•EˆK‰7!!S],•EˆK‰]M"i&h&%"Gb@•&$&Y8>"7![$"7!j<#BOQ!@97!! 9•&;„87i 78797k,!]#$("„87787[|!-G!^97!j! 9•&;„87i97k,!]#$("„87iK>7!@@~„87[$"„87!*"b‚b@A'$[$"7!|*"$H7!!! =I7!<+!;$,|Š‹@'Y8>"'$TV@P,|Š‹8;#U97!!Œ!!X„87[$"„87*"b97!!! Œ!!X„87L@_-f|$<!"f|@A'>J|#UH,|Š‹I#B&|b_$"G|<@A!;6&Db8|€!b•)8;-$;@@~;6„87^3|(")$Nb8V&#B^^†877!877,877Œ!!X„87‹w,|Š‹H|7!8Š87‹7&!!I@'-6b&"€!7!_$"#B-"G-V@P8;#U8;-$;^•7-@&!"7k87#7!!"7]Ž|Š‹S,|Š‹•|Š‹S 9!#"&8||Š‹;''P-„87575&!†@'>9'M|!"/'|Š‹8;†877!!-7&!†"„"88!-777k,!-7,„"88!-7]7Œ575&!† 9|5Ž77|Š‹S,Ž|Š‹ 98||Š‹!@D"[$"@V|Š‹!)b8V&#BD!#"&|Š‹†87|Š‹S7!!-7&!†"„"88!-777k,!-7,„"88!-7]7Œ575&!†|Š‹•#B@{W +X)SHELL_LINUX 3-18 3 SHELL---_LINUX}w!&/-)78_@+&;)!D")*; !-G!",-)787F@-)788;/&7!-G")*;&!-G!F788_")%"@$Y!-G!"-)788;,?78;,8;, ;$,9H788I<'P H !-G7;I8)'!-GN'w$,V,`10.YD"$8>@*"%"#$("!-;V8D)Y8>";&-|K"%b%"Y8>";87;@~Y8>"87887!-79#$("8>8;87/87!-732#O>"778;_;HILO>"4&'&8"%g--!87!-7""&"!8>!87[$"87|<@b$"87!87-|H ILO>"4&'&8"%g--!87!-7""&"!8>;"G|87$"87@|_b$"87!|87-H2ILO>"4&'&8"%g--!87!-78)Y8>"8"%g--!87!-7!);- 34&'&--!--! "&"!--!<8;Y8>";!--! ,7&Z[\30 !0]0^\208_2`0.[577 1. +Dabqrqr r Ăq pqrstr Â7H?I 75F"7 ?[go7 [5!87 ÊÔƠrƯĐƠrăărââârêôrơ-rđr rơr 2. cde20fde 30dg0 trrur 7--!--!SHELL_LINUX 4-18 4 SHELL---_LINUX Ăràrur sqq rrtrảrrãqrtrtrá rrrạằrqrẳrqá rẵẵ s pqrstrurĂqrẳràrrắqrá rr ULU905`[h09i000j09i0kl07\m056d80n8l82n0`2l07e 3[0`l8 átrá rrrvárrạrrằr r rđ Ărârrqràẳrvqár ẳrtru 9:55!!,7rr rqrÔrƠrqẵrô-rvrq rr rđ Ăr 7%?# ke 3[085n80[lm0`\208_2`0o0pde208[/`0q ặá rrảrôtrtrầrêqátrẳrẩrst ĂràárơqáẵrrÔrêqátrẳrràt Ăr-rqƠr átràt Ăr rvárƠr Ăẳrqrrđrơr trrurrêqátrẳrrẫấậrầrêqátrẳrẩ pqrstrur r5n80pde208[/` o0pde208[/`0q |7k,]j?F7rrÔr r rdk,]j?e7rÔr r rèqátrẳrơqáẵrrẵrvqárvqru ạÔằârđr Ăt-á rạĐằârẻẳ Ărơqátrắq ạƯằârtđq rẳ 788&r Ăq đr |788ặá r ầrêqátrẳrẩ g7( r rêả Ă 1SSn |71j7(n |d1j7(neg7 ẽđ Ărêả Ă 1:Sn |71j7n |d1j7neg8 ẻr 1n |71j8n |d1j8neg87 ẻr r-rêả Ă 1Sn |71j87n |d1j87neg ặ r 1n |71jn |d1jneg7 ặ r rảrêả Ă 1Sn |71j7n |d1j7ner rtđq rhl308/ s034[dl S q ĂrÔrêả Ărq ĂrĐ:S q ĂrÔrơđ Ărêả Ărq ĂrĐ q Ărẳràq r Ăqr g #B[\KKgo [\KKẽqáẵrrắqrvrẳrẵtr + s034[dl g87 qrơđ Ărđ Ăg87 qrđ rqârặrắqrƠrơđ Ărqrẳrẵt g ẳrẵtrđ rqrƠrơđ Ărqrắqâ g87 qrĂqràẳSHELL_LINUX 5-18 5 SHELL---_LINUXg87 qrqrà g%87 qrrét-á rẳrq rẳrĂq rhl308/ s034[dl : [F7%&j!7&% ẹ[a7%&j7&% ' UVVUtrr qắràqátrơqá 7àqátrơqá rrrrạtrÊrằ ẳrqrôrrá rqrá r 787 átràqqátrơqá rơđ Ăràt Ărạr Êằ ẳrqrôrrá rá rắq ^\208_2`0dg07t3403[l2 trru qắràqátrơqá rÔ 7ẳrqrá r átràqátrơqá rÔràt Ă 787qắràqátrơqá rĐ 7ẳrqrá rơqràqátrơqá rĐràt Ăr 787ẳrqrá rrơqràqátrơqá rĐrơđ Ăràt Ă pqrstr S?7ề\%H"Iề7ề K"%H7!Iề7gề787)"7d e^ề7!d,g7(e77ề"#"&\%H"Iề7879999777999999d,g7( e77ề"#"&K"%H7!Iề7877ềể!)"ễ8#7\%5K"%ề* >D@Uuutrru SHELL_LINUX 6-18 6 SHELL---_LINUXqắràqátrơqá rÔ 7àqátrơqá rÔràt Ă ẳrqrrá rá rqắr qắràqátrơqá rĐrrr7àqátrơqá rĐràt ĂrạtrÊrằ ẳrqrrá rá rrqắ qắràqátrơqá rƯ 7àqátrơqá rƯràt ĂrạtrÊrằ ẳrqrrá rá rrqắ 787ơđ Ărràqátrơqá r rrá ràt Ăr ẳrqrrá rá rắq pqrstru 9:559&778787d,g?e77ề,&7ề78d,g8?e77ề,7!7ề78d,g7(?e77ề,o7ề7877ề&&:,"-7_7"-7ề= vEvEU34&'& 2Z17ềể78-7,-7ề7b8V&ế@A$G4&'&3!" !" #$$SHELL_LINUX 7-18 7 SHELL---_LINUX %&'('%vEUwD " #$$)))*+))), ," #,$$)))-+))) .%(% %%))))+/)))H vE34&'&/0123''''''444444)566))7+/'0().8!3%9.:'';''';'%%7<=>(!'%%?+'+;@'%= ( /0(.!3%(A( B=+(CA(B% B=+($BM CD34&'&(@.'+''44444''+''44444SHELL_LINUX 8-18 8 SHELL---_LINUX''+:''44444''A''44444'' • "G|-f|&!7@*"&|"••• `I<+>#'MA&@*"#B@4W (Ox&DTV@P!#BB@7";;YB'8f|4&'&@[YB@>&@Õ#B4&@A>-8f|&&)566)=DE4)F;;<+4)&G/H D0(.;D3(=!L)&;)_<B'aKH'y#HUD[;@W)4!$N&/P8f|Jb20H!)!"„I)566)';.2</4>&';/;H%(%))I82</JJ''D4=!FB'8f|uFz{zKDKUU34ONB'8f|#B&|8"B8"B‚!@4bP8f|-;8;b#/P&'>!8fSHELL_LINUX 9-18 9 SHELL---_LINUXJ@7/_!<#BB'8f|JbG0-;8;B'8f|J"G|87@$bG?_!-|&'>!8;$"#'#$4b8V&>?X Ox&D|FAIz a8>7@$@A'P$|-;!8;P8f w8>77@#-!Y8>"|P8f| w'&!_!g_g_g% j&!-7#-!8f|4&'&H#B)&IF@|>;&8>NVNK j&!-7!-f|b8>#)F@;&8>N@VN@& 3'&j_gế8;->!"_ệ8>N@ j%&!-7!#$("-f|8>78G|$U[@;&8>NKVNK w!&@#-!!8847%[$"w&&'&;)8>!&&|8;8>@D"/!&34&'&!&ì--!ỉì!8ỉ }K~z? F'#|788 !"& |7"&H38.3I2 " L88)566+JKL; . ( (J9M-F!)9M-FNOP;+22Q-+4 R S=!Z[\3 #"1. KD^20[l0`[h0] --!ĩĩ--! ẵẵ sĐrẳrrqr átrẵẵ srÔrrvárãqrtrrrạtằ ^20[l0`[h0 --!--! ẵẵ srĐrqrẳrqrơqrãqrtrtrẵẵ srÔrrrơrrạắằ ^h08[e0n/012 340`l0[ld0 --!ĩĩ--! --!2ẻátrẵẵ srÔr rđ Ărqrẳrqrẵẵ sĐƠr átrơđ Ărqrẳrqrẵẵ sƯ SHELL_LINUX 10-18 10 [...]... standard output đên standard error ́ ̣ ́ Cú phap : ́ from>&destination 3 Ham ̀ Cú phap : ́ function-name ( ) { command1 commandN return } hoăc ̣ function function-name SHELL_ LINUX 11-18 11 SHELL -_LINUX { } command1 commandN return Trong đo, function-name là tên ham, lênh return sẽ kêt thuc ham ́ ̀ ̣ ́ ́ ̀ Goi ham : function-name ̣ ̀ Truyên tham số : function-name $arg1 $arg2 ̀ Lây tham... ̉ ́ ̀ ̀ ́ ̀ ̣ Ví dụ : shift 2 6 Phat sinh số ngâu nhiên ́ ̃ $RANDOM là 1 biên ham cua Bash (không phai là hăng sô) cho phep phat sinh số ngâu nhiên ́ ̀ ̉ ̉ ̀ ́ ́ ́ ̃ trong pham vi 0 – 32767 ̣ ví dụ : SHELL_ LINUX 12-18 12 SHELL -_LINUX #!/bin/bash MAXCOUNT=10 count=1 echo echo "$MAXCOUNT random numbers:" echo " -" while [ "$count" -le $MAXCOUNT ] # Generate 10 ($MAXCOUNT) random integers... thế tât cả chuôi trung vơi substring băng replacement ́ ̃ ̀ ́ ̀ Ví dụ : stringZ=abcABC123ABCabc echo ${stringZ/abc/xyz} echo ${stringZ//abc/xyz} SHELL_ LINUX # xyzABC123ABCabc # xyzABC123ABCxyz 15-18 15 SHELL -_LINUX Bai tập ̀ Bai 1 : Viêt chương trinh shell giai phương trinh bâc hai : ax2 + bx +c =0 vơi cac tham số a,b,c nhâp từ ̀ ́ ̀ ̉ ̀ ̣ ́ ́ ̣ ban phim và cac kêt quả chinh xac đên hai chữ... _filesize[$index]=$filesize let "index +=1" fi SHELL_ LINUX # trương thứ 5 cua kêt quả lênh ls –l là kich ̀ ̉ ́ ̣ ́ # thươc file ́ # gan mang file name ́ ̉ # gan mang file size ́ ̉ 16-18 16 SHELL -_LINUX done echo "Tong so tap tin : $index" for ((i=0 ; i myf this is my file nhân Ctrl+D ́ cat sẽ tao file myf chưa dong “this is my file” ̣ ́ ̀ Trong lâp trinh Linux, cac thiêt bị như ban... 2 nghiem" x1=$(echo "scale=2; -($b + sqrt($delta))/(2*$a)" | bc) echo "x1= $x1" x2=$(echo "scale=2; -($b - sqrt($delta))/(2*$a)" | bc) echo "x2= $x2" fi exit 0 Bai 2 : ̀ Viêt chương trinh shell liêt kê cac tâp tin trong thư muc nhâp vao từ ban phim mà có kich thươc > 4KB ́ ̀ ̣ ́ ̣ ̣ ̣ ̀ ̀ ́ ́ ́ theo dang sau : ̣ Tông số tâp tin ̉ ̣ Tâp tin 1 ̣ kich thươc ́ ́ tâp in n ̣ kich thươc ́ ́ #!/bin/bash... array2=( [0]="first element" [1]="second element" [3]="fourth element" ) echo echo echo echo ${array2[0]} ${array2[1]} ${array2[2]} ${array2[3]} SHELL_ LINUX # # # # first element second element không khơi tao nên có giá trị null ̉ ̣ fourth element 13-18 13 SHELL -_LINUX Ví dụ : arrayZ=( one two three four five five ) echo ${arrayZ[@]:0} # one two three four five five : tât cả cac phân tử ́ ́ ̀... đây cung dung để minh hoa lênh “shift “ Ban có thể gõ tham số cua chương ̣ ́ ̃ ̀ ̣ ̣ ̣ ̉ trinh theo 2 cach : ̀ ́ /convert –b radix –n number hoăc /conver –n number –b radix ̣ #!/bin/bash SHELL_ LINUX 17-18 17 SHELL -_LINUX if [ $# -ne 4 ]; then echo "Usage : $0 -b radix -n number or $0 -n number -b radix" exit 1 fi while [ "$1" ] do if [ "$1" = "-b" ];then ob="$2" case $ob in 16 ) basesystem="Hex";;... "obase=$ob;ibase=10;$num;" | bc) echo "$num Decimal number = $op in $basesystem number system (base=$ob)" exit 0 Ở đoan code trên thì quan trong nhât là dong “op=$(echo "obase=$ob;ibase=10;$num;" | bc)” Lênh nay ̣ ̣ ́ ̀ ̣ ̀ dung để chuyên cơ sô ̀ ̉ ́ End SHELL_ LINUX 18-18 18 . ()a@Pbc_'P$=34&'&7d&ed"f_$=e3'&g#B#O+%"Gbg7&h&"Y#O+7!""i"fi!!87H$"BIi!#&!7i#B%"Gbi%"Gbi*@D"bi!ii"i7j7k-6!!i!iiGi ]SHELL_ LINUX 1-18 1 SHELL- -- _LINUX* +,-./012 34056̉ ̣ 34&'&7%&&&h&'&. ()NOP-QRS&,TUVa@8)Y8>"•&‡;&-;8";$ SHELL_ LINUX 2-18 2 SHELL- -- _LINUX3 4&'&7!!! !2=![7!#B!-G'P<@A!$,•EˆK‰7!!S],•EˆK‰]M"i&h&%"Gb@•&$&Y8>"7![$"7!j<#BOQ!@97!!