testops.c revision 34f9b3eef6fdadbda0a846aa4d68691ac40eace5
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/***********************************************************************
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* This software is part of the ast package *
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz* Copyright (c) 1982-2009 AT&T Intellectual Property *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* and is licensed under the *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Common Public License, Version 1.0 *
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin* by AT&T Intellectual Property *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* A copy of the License is available at *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Information and Software Systems Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* AT&T Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Florham Park NJ *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* David Korn <dgk@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin***********************************************************************/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * tables for the test builin [[...]] and [...]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * This is the list of binary test and [[...]] operators
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinconst char sh_opttest[] =
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[-1c?\n@(#)$Id: test (AT&T Research) 2003-03-18 $\n]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+NAME?test - evaluate expression]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+DESCRIPTION?\btest\b evaluates expressions and indicates its "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "results based on the exit status. Option parsing is not "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "performed so that all arguments, including \b--\b are processed "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin " as operands. The evaluation of the "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "expression depends on the number of operands as follows:]{"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+0?Evaluates to false.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+1?True if argument is not an empty string.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+2?If first operand is \b!\b, the result is True if the second "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "operand an empty string. Otherwise, it is evaluated "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "as one of the unary expressions defined below. If the "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "unary operator is invalid and the second argument is \b--\b,"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "then the first argument is processed as an option argument.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+3?If first operand is \b!\b, the result is True if the second "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "and third operand evaluated as a unary expression is False. "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "Otherwise, the three operands are evaluaged as one of the "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "binary expressions listed below.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+4?If first operand is \b!\b, the result is True if the next "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "three operands are a valid binary expression that is False.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[If any \afile\a is of the form \b/dev/fd/\b\an\a, then file descriptor "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "\an\a is checked.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+?Unary expressions can be one of the following:]{"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-a \afile\a?True if \afile\a exists, obsolete.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-b \afile\a?True if \afile\a exists and is a block special file.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-c \afile\a?True if \afile\a exists and is a character special "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-d \afile\a?True if \afile\a exists and is a directory.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-e \afile\a?True if \afile\a exists.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-f \afile\a?True if \afile\a exists and is a regular file.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-g \afile\a?True if \afile\a exists and has its set-group-id bit "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-h \afile\a?True if \afile\a exists and is a symbolic link.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-k \afile\a?True if \afile\a exists and has its sticky bit on.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-l \afile\a?True if \afile\a exists and is a symbolic link.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-n \astring\a?True if length of \astring\a is non-zero.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-o \aoption\a?True if the shell option \aoption\a is enabled.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-p \afile\a?True if \afile\a exists and is a pipe or fifo.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-r \afile\a?True if \afile\a exists and is readable.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-s \afile\a?True if \afile\a exists and has size > 0.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-t \afildes\a?True if file descriptor number \afildes\a is "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "open and is associated with a terminal device.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-u \afile\a?True if \afile\a exists and has its set-user-id bit "
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz "[+-v \avarname\a?True if \avarname\a is a valid variable name that is set.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-w \afile\a?True if \afile\a exists and is writable.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-x \afile\a?True if \afile\a exists and is executable. For a "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "directory it means that it can be searched.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-z \astring\a?True if \astring\a is a zero length string.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-G \afile\a?True if \afile\a exists and group is the effective "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "group id of the current process.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-L \afile\a?True if \afile\a exists and is a symbolic link.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-N \afile\a?True if \afile\a exists and has been modified since "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "it was last read.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-O \afile\a?True if \afile\a exists and owner is the effective "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "user id of the current process.]"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz "[+-R \avarname\a?True if \avarname\a is a name reference.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+-S \afile\a?True if \afile\a exists and is a socket.]"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz "[+-V \afile\a?True if \afile\a exists and is a version "
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz "directory.]"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#endif /* SHOPT_FS_3D */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+?Binary expressions can be one of the following:]{"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+\astring1\a = \astring2\a?True if \astring1\a is equal to "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "\astring2\a.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+\astring1\a == \astring2\a?True if \astring1\a is equal to "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "\astring2\a.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+\astring1\a != \astring2\a?True if \astring1\a is not equal to "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "\astring2\a.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+\anum1\a -eq \anum2\a?True if numerical value of \anum1\a is "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "equal to \anum2\a.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+\anum1\a -ne \anum2\a?True if numerical value of \anum1\a is not "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "equal to \anum2\a.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+\anum1\a -lt \anum2\a?True if numerical value of \anum1\a is less "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "than \anum2\a.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+\anum1\a -le \anum2\a?True if numerical value of \anum1\a is less "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "than or equal to \anum2\a.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+\anum1\a -gt \anum2\a?True if numerical value of \anum1\a is "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "greater than \anum2\a.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+\anum1\a -ge \anum2\a?True if numerical value of \anum1\a is "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "greater than or equal to \anum2\a.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+\afile1\a -nt \afile2\a?True if \afile1\a is newer than \afile2\a "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "or \afile2\a does not exist.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+\afile1\a -ot \afile2\a?True if \afile1\a is older than \afile2\a "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "or \afile2\a does not exist.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+\afile1\a -ef \afile2\a?True if \afile1\a is another name for "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "\afile2\a. This will be true if \afile1\a is a hard link "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "or a symbolic link to \afile2\a.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"\n[expression]\n"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+EXIT STATUS?]{"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+0?Indicates that the specified expression is True.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+1?Indicates that the specified expression is False.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+>1?An error occurred.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+SEE ALSO?\blet\b(1), \bexpr\b(1)]"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzconst char test_opchars[] = "HLNRSVOGCaeohrwxdcbfugkv"