Test: Difference between revisions

From ICO wiki
Jump to navigationJump to search
Line 75: Line 75:
Arg1 -ge Arg2 - True if Arg1 is greater than or equal (ge) to Arg2
Arg1 -ge Arg2 - True if Arg1 is greater than or equal (ge) to Arg2
</pre>
</pre>
[http://en.wikipedia.org/wiki/Test_(Unix)]
[http://www.codewalkers.com/c/a/Miscellaneous/The-Test-in-the-UNIX-Shell/2/]


== Kasutatud kirjandus ==
== Kasutatud kirjandus ==

Revision as of 12:17, 2 January 2014

Gerli Kaunissaar AK41 2013

Sissejuhatus

Test on käsk, mis kontrollib faili tüüpe ja võrdleb väärtusi. Seda käsurea utiliiti kasutatakse UNIX-laadsetes operatsioonisüsteemides. Test käsuga on võimalik testida failde, stringide, loogiliste avaldiste ja muutujate kindlaid tunnuseid.

Süntaks

test EXPRESSION

või

[ EXPRESSION ]

Kui kasutada teist varjanti tuleb jälgida, et sulgude ja selle sees oleva avaldise vahel on alati tühik.

Kasutamine ja näited

Failid ja stringid

Sageli tuleb kontrollida faili omadusi. Me saame uurida kas fail on eksisteerib, kas meil on õigus kustutada, kirjutada, lugeda seda faili.

Järgnevad funktsioone kasutatakse parameetri moodustamiseks

-e FileName - FileName exists.

Kõik ülejäänud funktsioonid annavad tagasi true, kui objekt (fail või string) on olemas ja määratud tingimus on tõene.

FAILI FUNKTSIOONID
-b Filename - Returns a True exit value if the specified FileName exists
   and is a block special file.
-c FileName - FileName is a character special file.
-d FileName - FileName is a directory.
-f FileName - FileName is a regular file.
-g FileName - FileName's Set Group ID bit is set.
-h FileName - FileName is a symbolic link.
-k FileName - FileName's sticky bit is set.
-L FileName - FileName is a symbolic link.
-p FileName - FileName is a named pipe (FIFO).
-r FileName - FileName is readable by the current process.
-s FileName - FileName has a size greater than 0.
-t FileDescriptor - FileDescriptor is open and associated with a terminal.
-u FileName - FileName's Set User ID bit is set.
-w FileName - FileName's write flag is on. However, the FileName will
   not be writable on a read-only file system even if test indicates true.
-x FileName - FileName's execute flag is on.
   If the specified file exists and is a directory, the True exit value indicates
   that the current process has permission to change (chdir) into the directory.
file1 -nt file2 - file1 is newer than file2.
file1 -ot file2 - file1 is older than file2.
file1 -ef file2 - file1 is another name for file2. (symbolic link or hard link)
STRINGI FUNKTSIOONID
-n String1 - the length of the String1 variable is nonzero.
-z String1 - the length of the String1 variable is 0 (zero).
String1 = String2 - String1 and String2 variables are identical.
String1 != String2 - String1 and String2 variables are not identical.
String1 - String1 variable is not a null string.

[1]

NÄIDE: Kui fail kass.txt eksisteerib, siis kustutatakse see, kui faili ei ole siis ilmub ekraanile kirje faili ei ole.

if test -e kass.txt;
then rm kass.txt;
else echo faili ei ole
fi

Loogilised avaldised ja numbrid

! expression                 - True if the expression is false
expression_1 -a expression_2 - True if both of the expressions are true; it's a logical and (-a)
expression_1 -o expression_2 - True if either one of the expressions is true; it's a logical or (-o)
numbrid
Arg1 -eq Arg2 - True if Arg1 is equal (eq) to Arg2
Arg1 -ne Arg2 - True if Arg1 is not equal (ne) to Arg2
Arg1 -lt Arg2 - True if Arg1 is less than (lt) Arg2
Arg1 -le Arg2 - True if Arg1 is less than or equal (le) to Arg2
Arg1 -gt Arg2 - True if Arg1 is greater than (gt) Arg2
Arg1 -ge Arg2 - True if Arg1 is greater than or equal (ge) to Arg2

[2]

Kasutatud kirjandus

http://www.codewalkers.com/c/a/Miscellaneous/The-Test-in-the-UNIX-Shell/
http://unixhelp.ed.ac.uk/CGI/man-cgi?test
http://en.wikipedia.org/wiki/Test_(Unix)