home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Linux in a NutshellLinux in a NutshellSearch this book

8.5. Expressions

Expressions are used in @, if, and while statements to perform arithmetic, string comparisons, file testing, and so on. exit and set also specify expressions, as can the tcsh built-in command filetest. Expressions are formed by combining variables and constants with operators that resemble those in the C programming language. Operator precedence is the same as in C and can be remembered as follows:

  1. * / %

  2. + -

Group all other expressions inside parentheses. Parentheses are required if the expression contains <, >, &, or |.

8.5.1. Operators

Operators can be one of the following types.

8.5.1.5. File inquiry operators

Command substitution and filename expansion are performed on file before the test is performed. Operators can be combined (e.g., -ef). The following is a list of the valid file inquiry operators:

Operator

Description

-b file

The file is a block special file.

-c file

The file is a character special file.

-d file

The file is a directory.

-e file

The file exists.

-f file

The file is a plain file.

-g file

The file's set-group-ID bit is set.

-k file

The file's sticky bit is set.

-l file

The file is a symbolic link.

-L file

Apply any remaining operators to symbolic link, not the file it points to.

-o file

The user owns the file.

-p file

The file is a named pipe (FIFO).

-r file

The user has read permission.

-s file

The file has nonzero size.

-S file

The file is a socket special file.

-t file

file is a digit and is an open file descriptor for a terminal device.

-u file

The file's set-user-ID bit is set.

-w file

The user has write permission.

-x file

The user has execute permission.

-X file

The file is executable and is in the path, or is a shell built-in.

-z file

The file has 0 size.

!

Reverse the sense of any preceding inquiry.

Finally, tcsh provides the following operators, which return other kinds of information:

Operator

Description

-A[:] file

Last time file was accessed, as the number of seconds since the epoch. With a colon (:), the result is in timestamp format.

-C[:] file

Last time inode was modified. With a colon (:), the result is in timestamp format.

-D file

Device number.

-F file

Composite file identifier, in the form device:inode.

-G[:] file

Numeric group ID for the file. With a colon (:), the result is the group name if known, otherwise the numeric group ID.

-I file

Inode number.

-L file

The name of the file pointed to by symbolic link file.

-M[:] file

Last time file was modified. With a colon (:), the result is in timestamp format.

-N file

Number of hard links.

-P[:] file

Permissions in octal, without leading 0. With a colon (:), the result includes a leading 0.

-Pmode[:] file

Equivalent to -P file ANDed to mode. With a colon (:), the result includes a leading 0.

-U[:] file

Numeric user ID of the file's owner. With a colon (:), the result is the username if known, otherwise the numeric user ID.

-Z file

The file's size, in bytes.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.