Test: Difference between revisions

From ICO wiki
Jump to navigationJump to search
Gkauniss (talk | contribs)
Gkauniss (talk | contribs)
No edit summary
Line 60: Line 60:
fi
fi
</pre>
</pre>
 
=== Loogilised avaldised ja numbrid ===
<pre>
<pre>


</pre>
</pre>

Revision as of 22:01, 30 December 2013

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. Testiga on võimalik kontrollida faile, stringe, loogilisi avaldisi ja numbreid.

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.

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