Test: Difference between revisions
From ICO wiki
Jump to navigationJump to search
No edit summary |
No edit summary |
||
Line 45: | Line 45: | ||
file1 -ot file2 - file1 is older than file2. | file1 -ot file2 - file1 is older than file2. | ||
file1 -ef file2 - file1 is another name for file2. (symbolic link or hard link) | file1 -ef file2 - file1 is another name for file2. (symbolic link or hard link) | ||
-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. | |||
</pre> | </pre> | ||
NÄIDE: Kui fail kass.txt eksisteerib, siis kustutatakse see, kui faili ei ole siis ilmub ekraanile kirje faili ei ole. | NÄIDE: Kui fail kass.txt eksisteerib, siis kustutatakse see, kui faili ei ole siis ilmub ekraanile kirje faili ei ole. | ||
Line 55: | Line 61: | ||
<pre> | <pre> | ||
</pre> | </pre> |
Revision as of 20:49, 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 sulgude sees oleva avaldise vahel on alati tühik.
Kasutamine ja näited
Failid ja stringid
Me saame kontrollida kas fail on olemas, kas meil on õigus kustutade see isegi siis, kui see on kehtiv ja käivitatav fail.
Järgnev funktsioon
-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.
-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) -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