תרגול מס' 7

Embed Size (px)

DESCRIPTION

תרגול מס' 7. תוכניות סטנדרטיות ב- UNIX C-Shell. לי-טל משיח litalma@cs.technion.ac.il. UNIX תוכניות סטנדרטיות ב-. בכל מחשב אשר מותקנת בו מערכת הפעלה מסוג Unix מותקנות בנוסף מספר תוכנות סטנדרטיות אשר ניתן להיעזר בהן ניראה מספר תוכניות ודרכים לשלב בינהן. קבלת רשימת הקבצים במדריך. - PowerPoint PPT Presentation

Text of תרגול מס' 7

  • ' 7 -UNIXC-Shell

    - litalma@cs.technion.ac.il

  • UNIX - Unix

  • ls .

    :ls .

    ls -l

    ls -a ( "." " )> lsprogs

    > ls progshello

    > ls -ltotal 7 -rw-r--r-- 1 ari 2425 Mar 12 11:59 moshedrwx------ 2 ari 512 May 13 03:30 progs

    > ls -a. ..cshrc.loginmosheprogs

  • cat >cat file_1 file_2 file_k file_1,file_2,,file_k head [-n] [files] . -n n ( 10).>head -20 phone 20 phone

    tail [options] [files] -n n ( 10). +n n - .

  • myfile

    first3 " " pipelining > head 3 < myfile > first3> tail 2 < first3

  • Pipelining | program2 program1. , ,

    > cat myfile | head 3 | tail 2>lsaaabbbcccddd>ls | head 3aaabbbccc

  • tee tee [options] [files] piepeline [files]

    : myfile , :

    : -a [files] .

    > head 3 myfile | tee file1 file2 | tail 2

  • sort sort [options] [files] [files], ".

    :-b -d ( )-f uppercase/lowercase -m ( ).-n .-ofile file.-r .u- .+n n .

  • - sort > cat data WorldwhouldforFater> sort dataFaterWorldforwhould> sort data -fFaterforwhouldWorld> sort data -rwhouldforWorldFater> ls -ltotal 6-rw------- 1 romano root 23 Nov 8 23:09 data-rw------- 1 romano 368 243 Nov 8 23:12 ex1-rw------- 1 romano 368 428 Nov 8 23:22 ex2-rw------- 1 romano 368 0 Nov 10 13:30 ex3> ls -l | sort +4 > lsdata> more lsdatatotal 6-rw------- 1 romano 368 0 Nov 10 13:30 ex3-rw------- 1 romano root 0 Nov 10 13:31 lsdata-rw------- 1 romano root 23 Nov 8 23:09 data-rw------- 1 romano 368 243 Nov 8 23:12 ex1-rw------- 1 romano 368 428 Nov 8 23:22 ex2>

  • grep grep [options] [^]word [files] [files] word . " , >grep "It is" file :-c -h , -i uppercase/lowercase-l -n -v , word-w word ( )^word - word

  • - grep > lsex/ ex2 ex4 file2~ex1 ex3 file1~> ls | grep exex/ex1ex2ex3ex4> ls | grep -c ex5> more file1Arik !Have you heard news ?If not , listen !> cat file2Tomorrow we have a new exam !So we cannot go to Ran's birthday .By .> grep -v -n new * | sort | head -3file1:1:Arik !file1:3:If not , listen !file2:2:So we cannot go to Ran's birthday . > lsfile1 file2 typescript> cat file1 file2Arik !Have you heard news ?If not , listen !Tomorrow we have a new exam !So we cannot go to Ran's birthday .By .> cat file2 file1 | grep new | sort -d onews> more newsHave you heard news ?Tomorrow we have a new exam !

  • uniq uniq [options] [file1 [file2]] file1 , file2 ( file2, ).

    :-c .-d , .-u .-n - n ( )

    :

  • - uniq > more file3onetwotwothreethreethree> uniq file3 list> more listonetwothree> > more namesUriDanUriElenaAlexOfraUriOfra> sort names | uniq -dOfraUri>

  • cut cut options [files] cut files.

    : -c list , - list -f list , - list -dc -f . . c.

  • - cut > cat file1a11 a12 a13 a14 a15b21 b22 b23 b24 b25c31 c32 c33 c34 c35> cut -c1-3,5,8-10 file1a11a a1b21b b2c31c c3> cut -d" " -f2,4 file1a12 a14b22 b24c32 c34 , , .

    > cat file2a11:a12:a13 b21:b22 c31 c32 c33 > cat file2 | cut -d":" f1 a11b21 c31 c32 c33 > cat file2 | cut -d":" f3 a13 c31 c32 c33

  • wc wc [options] [files] ,

    :-c .-l .-w .

  • - wc > wc -l phonebook12 phonebook> wc -w bible333333 bible> wc -c data8843 data : filename

  • printf printf format strings string format. . :%s - strings.- %[-]m[.n]s m , ( ) - n. -.

  • - printf strings (%s)

    > echo $HOME/home/rotics> printf My files are in %s\n $HOMEMy files are in /home/rotics> printf number is : %10.5s 123456789anumber is: 12345> printf number is : #%-10.3s# %s\n "123456789a" xxxnumber is: #123 # xxx> printf My files are in %s\n $HOME my PCMy files are in /home/roticsMy files are in my PC

  • CSHELL Unix . shell Shell

    " prompt login prompt ( < ). prompt -shell , -shell , . shell prompt > echo hellohello

  • Shells in UNIX Shell . Unix shell . , " " . shells Unix: cshell, kshell, bourne shell . cshell shell . Unix . shell. Shell .

  • SHELL - Shell - shell : -shell . , -shell " " :Alias - History - File name expansion - - (script) shell . "" . shell , "". -C , Unix . shell. Shell .

  • Command Aliasesalias

    new name command name

    > alias del rm> del file2 file2.alias - aliases. , alias " :> aliasdel rm :alias cdex2 "cd ~mtm/public/0506b/ex2"

    Unix . shell. Shell .

  • history !! - !vi - - vihistory - . -shell " " history! - n -Shell

    >set history=100 100

  • File name expansions -UNIX , -Shell . , - Shell Wildcards* ? [] [ - ]a[rxz]b -> arb, axb, azb

  • File name expansions*.c c*AD* AD

    > gcc -c *.c .c

  • set = variable - value.Value cshell: . - $ $ variable

    > set v = abc> echo $vabc> set v = 123 > echo $v123

  • - cshell '@' . set. @

    : '@' . 2-3+4 5- 3

    > @ i = 3> echo $i3> @ i = $i + 1> echo $i4> @ i ++> echo $i5> set v = 12> @ v = $v + $i> echo $v17

  • - cshell, , ( ) ( " ).> set a = "abc def ghe"> echo $aabc def ghe

  • a a[i] -i acshell- a 1- ( 0-).

    cshell ( ) : > set v[3] = (12 abc 34) :set: syntax error > set v = (123 def ghi) > echo $v 123 def ghi > echo $v[2] def > set v[3] = ww > echo $v 123 def ww

  • a ,

    ${#a} a[m-n] -, - m - n a[-n] -, n- a[m-] -, -m a[*]

  • - > set a = ( aa bb cc dd ee )> echo $#a5>echo $a[3-]cc dd ee>echo $a[2-4]bb cc dd> echo $a[-3]aa bb cc a, shift a .> set v = ( go to the beach )> echo $v[1] go > shift v> echo $v[1]to> echo $vto the beach

  • . :> set a = abc def ghi> echo $a[1]abc def ghe . , > echo $a[2]a: Subscript out of range. " . >set b = ($a)>echo $babc def ghe>echo $b[2]def . :> set b = 123> set a = ${b}4> echo $a1234

  • Command substitution - cshell , , ( backquotes backticks),

    > echo you have `ls | wc -l` files in `pwd`you have 43 files in /home/rotics

    ( ls /home/rotics) - echo

  • Command substitution> cat listfile1 file2 file3> cat file1you are in file1Buy a Selkom phone> cat file2you are in file2buy Motorola Pelephone> cat file3you are in file3Im Grimberg Matzliah Ata Marviach> cat `cat list`you are in file1Buy a Selkom phoneyou are in file2buy Motorola Pelephoneyou are in file3Im Grimberg Mazliah Ata Marviach

  • CSHELL - -C-Shell -Macro Processor , : prompt , , C-Shell : . alias.

    C-shell: : . -Tab : . , :

  • )pipeline redirection(

    1. (" !) History Substitution2. . ( ) > echo AAAAAA> echo !! echo echo AAAecho AAA3. alias alias substituion.4. variable substitution5. File name substitution6. command substitution. back-quoted string (`... `)

  • . : . -Shell ( ) : (full path name). C-Shell . path. C-shell " Shell . (history) (set/unset/shift) alias (alias/unalias) working directory (cd) ( )

  • I/O redirectionI/O redirection " -Shell. : // I/O redirection, " - Shell

    Pipeline-pipeline " |. , Shell standard output pipeline standard input

    -shell . tab ( ) shell .

  • ` - (back quote)" - (double quote)' - (single quote)back quotes command substitution. -shell -back quotes . . -shell single quotes double quotes Shell ( ) . " -Shell . - double quoted string . single quoted string :> set a = AAA> echo a=$aa=AAA> echo a=$aa=$a single or double quoted strings. back quotes double quote shell .