Κελύφη, Μεταβλητές και Προγραμματισμός

  • View
    36

  • Download
    1

Embed Size (px)

DESCRIPTION

, . C & Unix , B . lpis . csd . auth . gr / curriculum / C + Unix / UNCL 202. html. . - PowerPoint PPT Presentation

Transcript

  • , C & Unix , B lpis.csd.auth.gr/curriculum/C+Unix/UNCL202.html

  • UNIX

  • (HOME ) home directory . To home directory UNIX, . HOME login.

  • (PATH ) , (:) . calculator /users/bob/mybin/ calculator , PATH /users/bob/mybin.

  • (LOGNAME, MAIL ) LOGNAME login name . MAIL e-mails .

  • (SHELL, TERM ) SHELL . (.. /bin/csh) SHELL. TERM . vi .

  • UNIX . "$".

  • - $ cd $ home directory . $ , . home directory /users/bob, cd $HOME cd /users/bob.

  • - echo echo . $ echo Hallo worldHallo world$ echo $HOME/users/bob$ echo $PATH/bin/:/usr/local/bin/:/users/bob/:/users/bob/mybin/

  • - set set, .BASH=/usr/bin/bashMAKE_MODE=unixNUMBER_OF_PROCESSORS=1OSTYPE=cygwinPATH='/usr/local/bin:/usr/bin:/bin:...:.'PROMPT='$P$G'SESSIONNAME=ConsoleSHELL=/bin/bashTERM=cygwin

  • (.. LOGNAME) , prompt UNIX , "=" . $ TERM = vtlOO$ = /users/billy/mybin

  • PATH PATH . UNIX , PATH . PATH . $

  • PATH - /users/billy/mybin PATH, :$ echo $PATH/bin/:/usr/local/bin/:/users/billy/$ PATH=$PATH:/users/billy/mybin$ echo $PATH/bin/:/usr/local/bin/:/users/billy/:/users/billy/mybin

  • . MYPLACE /users/maria/documents/$ MYPLACE=/users/maria/documents/

  • $ $ X=2$ echo $X2$ $X=3bash: 2=3: command not found

  • unset:unset :unset X

  • . . , .

  • . .

  • env. $ envHOME=/users/billiePWD=/users/billie/papersMAILRC=/users/billie/mail/.mailrc...

  • UNIX , export. $ export PAPERS$ envHOME=/users/jimmyPWD=/users/jimmy/papersMAILRC=/users/jimmy/mail/.mailrcPATH=/usr/bin:/usr/local/binPAPERS=/users/jimmy/papers $ PAPERS=/users/jimmy/papers$ envHOME=/users/jimmyPWD=/users/jimmy/papersMAILRC=/users/jimmy/mail/.mailrcPATH=/usr/bin:/usr/local/bin PAPERS PAPERS export

  • history . $ lsa.txt documents games$ cd games$ lsnfs3fifa2000$ cd ..$ history112 ls113 cd games114 cd ..115 history

  • history HISTSIZE. HISTSIZE 500 ( CYGWIN) .$ HISTSIZE=10

  • . , (.. cat text1.txt) , TAB. .

  • - $ lsAlaska California Calories Kentucky$ cat A cat Alaska. A.$ cat Cali cat California. 4 Calories.

  • (shell scripts)

  • : UNIX ( ) ..

  • . DOS batch files (.bat) shell scripts UNIX.

  • , . prompt UNIX

  • - : cal, pwd ls -la, (.. my_first_script.sh), editor 3 cal pwdls la

  • - , my_first_script.sh . :$ chmod ugo+x my_first_script.sh$ chmod a+x my_first_script.sh

  • - . $ my_first_script.sh PATH , "./". $./my_first_script.sh

  • - , , 3 : cal, pwd, ls -la

  • , . .

  • , echo. echo . , .. echo Hello world , echo . .. echo $

  • echo, $. echo PATH PATH echo $PATH PATH

  • read. : read ( ), (string) . read NAME

  • / , UNIX

  • echo Please type a command:read COMecho Now type the name of a file:read FN$COM > $FN COM FN COM FN

  • . , ( ) prompt UNIX . .. ls C, (.. ls -la).

  • UNIX , . scripts .

  • :0 ,1 ,2 . . .$ grep Hallo greetings.txt 3 0 2 :0 = grep1 = Hallo2 = greetings.txt

  • - , - prompt UNIX. :$1 > $2 rd.sh script

  • - ls -la: $ rd.sh ls la out.txt . ls -la :0 = rd.sh1 = ls2 = -la3 = out.txt ls '-la'

  • - ls la , . $ rd.sh ls la out.txt :0 = rd.sh1 = ls la2 = out.txt $1 > $2 script, ls la > out.txt

  • . if case.

  • if - if 1 then 1else 2fi 1. ( 0), 1. ( ), 2.

  • if else if , :if 1then 1fi 1 , 1 1 .

  • if 1 script results nick email , results :if mail nick < resultsthenrm f resultsecho !elseecho !fi

  • ... A > 5 = Peter UNIX test ( 0) 1 () test ,

  • N1 eq N21=2test $NUM eq 0N1 ne N222test $NUM ne $NUM2N1 gt N21>2test $NUM gt 1000N1 ge N212test $NUM ge 10N1 lt N21

  • if 2 script 1 2.

  • if 2if test a $1 thenif test $2 eq 1 thensort $1 > temprm f $1mv temp $1elseif test $2 eq 2 thensort r $1 > temprm f $1mv temp $1elseecho 1 2!fifielseecho fi temp -1 1 ? 2 1? -1 temp -1 2 2? , ... 2 1

  • test (.. test $N eq 0) (&&) (). test $N gt 0 && test $N le 10 0 N (0,10] 1 .

  • CTRL-C print-queue, pqueue.log print-queue : script

  • Script pqueue.shprint-queueif test -a pqueue.log thenrm pqueue.log fi ( CTRL-C) script pqueue.log,

  • . script . for, while until.

  • for for:) )

  • for for in do done . .., 0 - 10for I in 0 2 4 6 8 10doecho $Idone 0 2 4 6 8 10

  • wildcards for wildcards * ? for X in *.txtdoecho File: $Xcat $Xdone txt

  • for for do done script ($1, $2 ...). !

  • for - script sort_file, script ( multi_sort) :for FILEdosort_file $FILE 1done !

  • for - :$ multi_sort a.txt b.txt test2.txt :$ sort_file a.txt 1$ sort_file b.txt 1$ sort_file test2.txt 1

  • while while :while 1do 1done while 1 1 ( 0).

  • until until :until 1do 1done until 1 1 .

  • 6 5 .. cw txt1.txt out.dat , wildcards.. cw *.txt out.dat

  • script cw.sh:for FILE in $1docw5 $FILE $2donedisplay $2 permissions:$ chmod a+x cw.sh 5 1

  • script:$ cw.sh *.txt out.dat quotes wildcards script :$ cw.sh *.txt out.dat :$ cw.sh file1.txt ... filen.txt out.dat

  • batch Command Window Microsoft Windows MS-Windows batch :for %%x in ( %1 ) do cw5 %%x %2display %2 cw.bat Windows .bat

  • batch files script files % $ %1, %2, ... FOR %% (.. %%x) % (.. %PATH%)

  • C:\>echo %PATH%C:\Program Files\Common Files\Roxio Shared\DLLShared;C:\DJGPP\BIN;C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files\Microsoft Visual Studio\Common\Tools;C:\Program Files\Microsoft Visual Studio\VC98\bin;C:\BC5\BIN;C:\Program Files\Java\j2re1.4.2_06\bin;C:\BC5\BIN;

  • Unix set set x=3 set x echo %x% set x=

  • batch file batch file batch file:echo offfor %%x in ( %1 ) do cw5 %%x %2display %2

  • batch file echo off ! batch file echo off @@echo offfor %%x in ( %1 ) do cw5 %%x %2display %2

  • batch file @ @for %%x in ( %1 ) do cw5 %%x %2display %2

  • IF-THENIF [NOT] ERRORLEVEL number command numberIF [NOT] string1==string2 command strings ( ) IF [NOT] EXIST filename command filename

  • Batch pqueue.batprint-queueif EXIST pqueue.log del pqueue.log ( CTRL-C) script pqueue.log,

  • UNIX CTRL-C print-queue.exe, batch file batch file yes no batch

  • ^CTerminate batch job (Y/N)? n

  • pause batch file :Press any key to continue . . .

  • pause - for %%x in ( %1 ) do cw5 %%x %2echo I will display the resultpausedisplay %2 :C:\>cw.bat text*.txt out.datI will display the resultPress any key to continue . . . 1 Aristotle 3 CLIPS ...

  • batch files remrem The following starts the queueprint-queuerem The following deletes the logif EXIST pqueue.log del pqueue.log

  • goto batch files labels goto label batch file

  • goto if EXIST %1 goto continueecho File %1 does not exist!goto end:continueif %2==1 goto 1if %2==2 goto 2echo 2nd arg must be 1 or 2!goto end:1sort %1 > tempdel %1rename temp %1goto end:2sort r %1 > tempdel %1rename temp %1goto end:end temp -1 1 ? 2 1? -1 temp -1 2 2? , ... 2 1 OK 1