Test: Difference between revisions

From ICO wiki
Jump to navigationJump to search
Gkauniss (talk | contribs)
No edit summary
Gkauniss (talk | contribs)
No edit summary
Line 27: Line 27:
-c FileName - FileName is a character special file.
-c FileName - FileName is a character special file.
-d FileName - FileName is a directory.
-d FileName - FileName is a directory.
-f FileName - FileName is a regular file.
-f FileName - FileName is a regular file.
-g FileName - FileName's Set Group ID bit is set.
-g FileName - FileName's Set Group ID bit is set.
Line 39: Line 38:
-u FileName - FileName's Set User ID bit is set.
-u FileName - FileName's Set User ID bit is set.
-w FileName - FileName's write flag is on. However, the FileName will
-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.
  not be writable on a read-only file system even if test indicates true.
-x FileName - FileName's execute flag is on.
-x FileName - FileName's execute flag is on.
If the specified file exists and is a directory, the True exit value indicates
  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.
  that the current process has permission to change (chdir) into the directory.
file1 -nt file2 - file1 is newer than file2.
file1 -nt file2 - file1 is newer than file2.
file1 -ot file2 - file1 is older than file2.
file1 -ot file2 - file1 is older than file2.

Revision as of 20:41, 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Ä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