IEEE P1003.2 Draft 11.2 - September 1991 Copyright (c) 1991 by the Institute of Electrical and Electronics Engineers, Inc. 345 East 47th Street New York, NY 10017, USA All rights reserved as an unpublished work. This is an unapproved and unpublished IEEE Standards Draft, subject to change. The publication, distribution, or copying of this draft, as well as all derivative works based on this draft, is expressly prohibited except as set forth below. Permission is hereby granted for IEEE Standards Committee participants to reproduce this document for purposes of IEEE standardization activities only, and subject to the restrictions contained herein. Permission is hereby also granted for member bodies and technical committees of ISO and IEC to reproduce this document for purposes of developing a national position, subject to the restrictions contained herein. Permission is hereby also granted to the preceding entities to make limited copies of this document in an electronic form only for the stated activities. The following restrictions apply to reproducing or transmitting the document in any form: 1) all copies or portions thereof must identify the document's IEEE project number and draft number, and must be accompanied by this entire notice in a prominent location; 2) no portion of this document may be redistributed in any modified or abridged form without the prior approval of the IEEE Standards Department. Other entities seeking permission to reproduce this document, or any portion thereof, for standardization or other activities, must contact the IEEE Standards Department for the appropriate license. Use of information contained in this unapproved draft is at your own risk. IEEE Standards Department Copyright and Permissions 445 Hoes Lane, P.O. Box 1331 Piscataway, NJ 08855-1331, USA +1 (908) 562-3800 +1 (908) 562-1571 [FAX] Part 2: SHELL AND UTILITIES P1003.2/D11.2 like a=-1 In order to permit implementations to deal with backward compatibility as they see fit, the behavior of this one ambiguous construct was made undefined. (At least three implementations have been known to support this change already, so the degree of change involved should not be great.) The % operator is the mathematical remainder operator when scale is zero. The behavior of this operator for other values of scale is from traditional implementations of bc, and has been maintained for the sake of existing applications despite its nonintuitive nature. The bc utility always uses the period (.) character to represent a radix point, regardless of any decimal-point character specified as part of the current locale. In languages like C or awk, the period character is used in program source, so it can be portable and unambiguous, while the locale-specific character is used in input and output. Because there is no distinction between source and input in bc, this arrangement would not be possible. Using the locale-specific character in bc's input would introduce ambiguities into the language; consider the following example in a locale with a comma as the decimal-point character: define f(a,b) { ... } ... f(1,2,3) Because of such ambiguities, the period character is used in input. Having input follow different conventions from output would be confusing in either pipeline usage or interactive usage, so period is also used in output. Traditional implementations permit setting ibase and obase to a broader range of values. This includes values less than 2, which were not seen as sufficiently useful to standardize. These implementations do not interpret input properly for values of ibase outside greater than 16. This is because numeric constants are recognized syntactically, rather than lexically, as described in the standard. They are built from lexical tokens of single hexadecimal digits and periods. Since s between tokens are not visible at the syntactic level, it is not possible to properly recognize the multidigit ``digits'' used in the higher bases. The ability to recognize input in these bases was not considered useful enough to require modifying these implementations. Note that the recognition of numeric constants at the syntactic level is not a problem Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 4.3 bc - Arbitrary-precision arithmetic language 381 P1003.2/D11.2 INFORMATION TECHNOLOGY--POSIX with conformance to the standard, as it does not impact the behavior of portable applications (and correct bc programs). Traditional implementations also accept input with all of the digits 0-9 and A-F regardless of the value of ibase; since digits with value greater than or equal to ibase are not really appropriate, the behavior when they appear is undefined, except for the common case of ibase=8; /* Process in octal base */ ... ibase=A /* Restore decimal base */ In some historical implementations, if the expression to be written is an uninitialized array element, a leading character and/or up to four leading 0 characters may be output before the character zero. This behavior is considered a bug; it is unlikely that any currently portable application relies on echo 'b[3]' | bc returning 00000 rather than 0. Exact calculation of the number of fractional digits to output for a given value in a base other than 10 can be computationally expensive. Traditional implementations use a faster approximation, and this is permitted. Note that the requirements apply only to values of obase that the standard requires implementations to support (in particular, not to 1, 0, or negative bases, if an implementation supports them as an extension). END_RATIONALE Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 382 4 Execution Environment Utilities Part 2: SHELL AND UTILITIES P1003.2/D11.2 4.4 cat - Concatenate and print files 4.4.1 Synopsis cat [-u] [_f_i_l_e ...] 4.4.2 Description The cat utility reads files in sequence and writes their contents to the standard output in the same sequence. 4.4.3 Options The cat utility shall conform to the utility argument syntax guidelines described in 2.10.2. The following option shall be supported by the implementation: -u Write bytes from the input file to the standard output without delay as each is read. 4.4.4 Operands The following operand shall be supported by the implementation: _f_i_l_e A pathname of an input file. If no _f_i_l_e operands are specified, the standard input is used. If a _f_i_l_e is -, the cat utility shall read from the standard input at that point in the sequence. The cat utility shall not close and reopen standard input when it is referenced in this way, but shall accept multiple occurrences of - as a _f_i_l_e operand. 4.4.5 External Influences 4.4.5.1 Standard Input The standard input is used only if no _f_i_l_e operands are specified, or if a _f_i_l_e operand is -. See Input Files. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 4.4 cat - Concatenate and print files 383 P1003.2/D11.2 INFORMATION TECHNOLOGY--POSIX 4.4.5.2 Input Files The input files can be any file type. 4.4.5.3 Environment Variables The following environment variables shall affect the execution of cat: LANG This variable shall determine the locale to use for the locale categories when both LC_ALL and the corresponding environment variable (beginning with LC_) do not specify a locale. See 2.6. LC_ALL This variable shall determine the locale to be used to override any values for locale categories specified by the settings of LANG or any environment variables beginning with LC_. LC_CTYPE This variable shall determine the locale for the interpretation of sequences of bytes of text data as characters (e.g., single- versus multibyte characters in arguments). LC_MESSAGES This variable shall determine the language in which messages should be written. 4.4.5.4 Asynchronous Events Default. 4.4.6 External Effects 4.4.6.1 Standard Output The standard output shall contain the sequence of bytes read from the input file(s). Nothing else shall be written to the standard output. 4.4.6.2 Standard Error Used only for diagnostic messages. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 384 4 Execution Environment Utilities Part 2: SHELL AND UTILITIES P1003.2/D11.2 4.4.6.3 Output Files None. 4.4.7 Extended Description None. 4.4.8 Exit Status The cat utility shall exit with one of the following values: 0 All input files were output successfully. >0 An error occurred. 4.4.9 Consequences of Errors Default. BEGIN_RATIONALE 4.4.10 Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2) _E_x_a_m_p_l_e_s_,__U_s_a_g_e Historical versions of the cat utility include the options -e, -t, and -v, which permit the ends of lines, s, and invisible characters, respectively, to be rendered visible in the output. The working group omitted these options because they provide too fine a degree of control over what is made visible, and similar output can be obtained using a command such as: sed -n -e 's/$/$/' -e l pathname The -s option was omitted because it corresponds to different functions in BSD and System V-based systems. The BSD -s option to squeeze blank lines will be handled by more -s in the UPE. The System V -s option to silence error messages can be accomplished by redirecting the standard error. An alternative to cat-s is the following shell script using sed: Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 4.4 cat - Concatenate and print files 385 P1003.2/D11.2 INFORMATION TECHNOLOGY--POSIX sed -n ' # Write non-empty lines. /./ { p d } # Write a single empty line, then look for more empty lines. /^$/ p # Get next line, discard the held (empty line), # and look for more empty lines. :Empty /^$/ { N s/.// b Empty } # Write the non-empty line before going back to search # for the first in a set of empty lines. p ' Note that the BSD documentation for cat uses the term ``blank line'' to mean the same as the POSIX ``empty line''; a line consisting only of a . The BSD -n option is omitted because similar functionality can be obtained from the -n option of the pr utility. The -u option is included here for its value in prototyping nonblocking reads from FIFOs. The intent is to support the following sequence: mkfifo foo cat -u foo > /dev/tty13 & cat -u > foo It is unspecified whether standard output is or is not buffered in the default case. This is sometimes of interest when standard output is associated with a terminal, since buffering may delay the output. The presence of the -u option guarantees that unbuffered I/O is available. It is implementation dependent whether the cat utility buffers output if the -u option is not specified. Traditionally, the -u option is implemented using the BSD _s_e_t_b_u_f_f_e_r() function, the System V _s_e_t_b_u_f() function, or the C Standard {7} _s_e_t_v_b_u_f() function. The following command cat myfile writes the contents of the file myfile to standard output. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 386 4 Execution Environment Utilities Part 2: SHELL AND UTILITIES P1003.2/D11.2 The following command cat doc1 doc2 > doc.all concatenates the files doc1 and doc2 and writes the result to doc.all. Because of the shell language mechanism used to perform output redirection, a command such as this: cat doc doc.end > doc causes the original data in doc to be lost. Due to changes made to subclause 2.11.4 in Draft 11, the description of the _f_i_l_e operand now states that - must be accepted multiple times, as in historical practice. This allows the command: cat start - middle - end > file when standard input is a terminal, to get two arbitrary pieces of input from the terminal with a single invocation of cat. Note, however, that if standard input is a regular file, this would be equivalent to the command: cat start - middle /dev/null end > file because the entire contents of the file would be consumed by cat the first time - was used as a _f_i_l_e operand and an end-of-file condition would be detected immediately when - was referenced the second time. _H_i_s_t_o_r_y__o_f__D_e_c_i_s_i_o_n_s__M_a_d_e None. END_RATIONALE Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 4.4 cat - Concatenate and print files 387 P1003.2/D11.2 INFORMATION TECHNOLOGY--POSIX 4.5 cd - Change working directory 4.5.1 Synopsis cd [_d_i_r_e_c_t_o_r_y] 4.5.2 Description The cd utility shall change the working directory of the current shell execution environment; see 3.12. When invoked with no operands, and the HOME environment variable is set to a nonempty value, the directory named in the HOME environment variable shall become the new working directory. If HOME is empty or is undefined, the default behavior is implementation defined. 4.5.3 Options None. 4.5.4 Operands The following operands shall be supported by the implementation: _d_i_r_e_c_t_o_r_y An absolute or relative pathname of the directory that becomes the new working directory. The interpretation of a relative pathname by cd depends on the CDPATH environment variable. If _d_i_r_e_c_t_o_r_y is -, the results are implementation defined. 4.5.5 External Influences 4.5.5.1 Standard Input None. 4.5.5.2 Input Files None. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 388 4 Execution Environment Utilities Part 2: SHELL AND UTILITIES P1003.2/D11.2 4.5.5.3 Environment Variables The following environment variables shall affect the execution of cd: CDPATH A colon-separated list of pathnames that refer to directories. If the _d_i_r_e_c_t_o_r_y operand does not begin with a slash (/) character, and the first component is not dot or dot-dot, cd shall search for _d_i_r_e_c_t_o_r_y relative to each directory named in the CDPATH variable, in the order listed. The new working directory shall be set to the first matching directory found. An empty string in place of a directory pathname represents the current directory. If CDPATH is not set, it shall be treated as if it were an empty string. HOME The name of the home directory, used when no _d_i_r_e_c_t_o_r_y operand is specified. LANG This variable shall determine the locale to use for the locale categories when both LC_ALL and the corresponding environment variable (beginning with LC_) do not specify a locale. See 2.6. LC_ALL This variable shall determine the locale to be used to override any values for locale categories specified by the settings of LANG or any environment variables beginning with LC_. LC_CTYPE This variable shall determine the locale for the interpretation of sequences of bytes of text data as characters (e.g., single- versus multibyte characters in arguments). LC_MESSAGES This variable shall determine the language in which messages should be written. 4.5.5.4 Asynchronous Events Default. 4.5.6 External Effects Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 4.5 cd - Change working directory 389 P1003.2/D11.2 INFORMATION TECHNOLOGY--POSIX 4.5.6.1 Standard Output If a nonempty directory name from CDPATH is used, an absolute pathname of the new working directory shall be written to the standard output as follows: "%s\n", <_n_e_w _d_i_r_e_c_t_o_r_y> Otherwise, there shall be no output. 4.5.6.2 Standard Error Used only for diagnostic messages. 4.5.6.3 Output Files None. 4.5.7 Extended Description None. 4.5.8 Exit Status The cd utility shall exit with one of the following values: 0 The directory was successfully changed. >0 An error occurred. 4.5.9 Consequences of Errors The working directory remains unchanged. BEGIN_RATIONALE 4.5.10 Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2) _E_x_a_m_p_l_e_s_,__U_s_a_g_e _E_d_i_t_o_r'_s _N_o_t_e: _A _b_a_l_l_o_t_e_r _r_e_q_u_e_s_t_e_d _t_h_a_t _t_h_e _f_o_l_l_o_w_i_n_g _r_a_t_i_o_n_a_l_e _b_e 2 _h_i_g_h_l_i_g_h_t_e_d _i_n _t_h_e _D_1_1._2 _r_e_c_i_r_c_u_l_a_t_i_o_n. 2 Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 390 4 Execution Environment Utilities Part 2: SHELL AND UTILITIES P1003.2/D11.2 Since cd affects the current shell execution environment, it is generally provided as a shell regular built-in. If it is called in a subshell or 1 separate utility execution environment, such as one of the following: 1 (cd /tmp) 1 nohup cd 1 find . -exec cd {} \; 1 it will not affect the working directory of the caller's environment. 1 The use of the CDPATH was introduced in the System V shell. Its use is analogous to the use of the PATH variable in the shell. Earlier systems such as the BSD C-shell used a shell parameter cdpath for this purpose. _H_i_s_t_o_r_y__o_f__D_e_c_i_s_i_o_n_s__M_a_d_e A common extension when HOME is undefined is to get the login directory from the user database for the invoking user. This does not occur on System V implementations. Not included in this description are the features from the KornShell such as setting OLDPWD, toggling current and previous directory (cd -), and the two-operand form of cd (cd _o_l_d _n_e_w). This standard does not specify the results of cd - or of calls with more than one operand. Since these extensions are mostly used in interactive situations, they may be considered for inclusion in POSIX.2a. The result of cd - and of using no arguments with HOME unset or null have been made implementation defined at the request of the POSIX.6 security working group. The setting of the PWD variable was removed from earlier drafts, as it can be replaced by $(pwd). END_RATIONALE Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 4.5 cd - Change working directory 391 P1003.2/D11.2 INFORMATION TECHNOLOGY--POSIX 4.6 chgrp - Change file group ownership 4.6.1 Synopsis chgrp [-R] _g_r_o_u_p _f_i_l_e ... 4.6.2 Description The chgrp utility shall set the group ID of the file named by each _f_i_l_e operand to the group ID specified by the _g_r_o_u_p operand. For each _f_i_l_e operand, it shall perform actions equivalent to the POSIX.1 {8} _c_h_o_w_n() function, called with the following arguments: (1) The _f_i_l_e operand shall be used as the _p_a_t_h argument. (2) The user ID of the file shall be used as the _o_w_n_e_r argument. (3) The specified _g_r_o_u_p _I_D shall be used as the _g_r_o_u_p argument. 4.6.3 Options The chgrp utility shall conform to the utility argument syntax guidelines described in 2.10.2. The following option shall be supported by the implementation: -R Recursively change file group IDs. For each _f_i_l_e operand that names a directory, chgrp shall change the group of the directory and all files in the file hierarchy below it. 4.6.4 Operands The following operands shall be supported by the implementation: _g_r_o_u_p A group name from the group database or a numeric group ID. Either specifies a group ID to be given to each file named by one of the _f_i_l_e operands. If a numeric _g_r_o_u_p operand exists in the group database as a group name, the group ID number associated with that group name is used as the group ID. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 392 4 Execution Environment Utilities Part 2: SHELL AND UTILITIES P1003.2/D11.2 _f_i_l_e A pathname of a file whose group ID is to be modified. 4.6.5 External Influences 4.6.5.1 Standard Input None. 4.6.5.2 Input Files None. 4.6.5.3 Environment Variables The following environment variables shall affect the execution of chgrp: LANG This variable shall determine the locale to use for the locale categories when both LC_ALL and the corresponding environment variable (beginning with LC_) do not specify a locale. See 2.6. LC_ALL This variable shall determine the locale to be used to override any values for locale categories specified by the settings of LANG or any environment variables beginning with LC_. LC_CTYPE This variable shall determine the locale for the interpretation of sequences of bytes of text data as characters (e.g., single- versus multibyte characters in arguments). LC_MESSAGES This variable shall determine the language in which messages should be written. 4.6.5.4 Asynchronous Events Default. 4.6.6 External Effects Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 4.6 chgrp - Change file group ownership 393 P1003.2/D11.2 INFORMATION TECHNOLOGY--POSIX 4.6.6.1 Standard Output None. 4.6.6.2 Standard Error Used only for diagnostic messages. 4.6.6.3 Output Files None. 4.6.7 Extended Description None. 4.6.8 Exit Status The chgrp utility shall exit with one of the following values: 0 The utility executed successfully and all requested changes were made. >0 An error occurred. 4.6.9 Consequences of Errors If, when invoked with the -R option, chgrp attempts but fails to change the group ID of a particular file in a specified file hierarchy, it shall continue to process the remaining files in the hierarchy. If chgrp cannot read or search a directory within a hierarchy, it shall continue to process the other parts of the hierarchy that are accessible. BEGIN_RATIONALE 4.6.10 Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2) _E_x_a_m_p_l_e_s_,__U_s_a_g_e The System V and BSD versions use different exit status codes. Some implementations used the exit status as a count of the number of errors that occurred; this practice is unworkable since it can overflow the range of valid exit status value. The working group chose to mask these by specifying only 0 and >0 as exit values. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 394 4 Execution Environment Utilities Part 2: SHELL AND UTILITIES P1003.2/D11.2 _H_i_s_t_o_r_y__o_f__D_e_c_i_s_i_o_n_s__M_a_d_e The functionality of chgrp is described substantially through references to functions in POSIX.1 {8}. In this way, there is no duplication of effort required for describing the interactions of permissions, multiple groups, etc. END_RATIONALE 4.7 chmod - Change file modes 4.7.1 Synopsis chmod [-R] _m_o_d_e _f_i_l_e ... 4.7.2 Description The chmod utility shall change any or all of the file mode bits of the file named by each _f_i_l_e operand in the way specified by the _m_o_d_e operand. It is implementation defined whether and how the chmod utility affects any alternate or additional file access control mechanism (see _f_i_l_e _a_c_c_e_s_s _p_e_r_m_i_s_s_i_o_n_s in 2.2.2.55) being used for the specified file. Only a process whose effective user ID matches the user ID of the file, or a process with the appropriate privileges, shall be permitted to change the file mode bits of a file. 4.7.3 Options The chmod utility shall conform to the utility argument syntax guidelines described in 2.10.2. The following option shall be supported by the implementation: -R Recursively change file mode bits. For each _f_i_l_e operand that names a directory, chmod shall change the file mode bits of the directory and all files in the file hierarchy below it. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 4.7 chmod - Change file modes 395 P1003.2/D11.2 INFORMATION TECHNOLOGY--POSIX 4.7.4 Operands The following operands shall be supported by the implementation: _m_o_d_e Represents the change to be made to the file mode bits of each file named by one of the _f_i_l_e operands, as described in 4.7.7. _f_i_l_e A pathname of a file whose file mode bits are to be modified. 4.7.5 External Influences 4.7.5.1 Standard Input None. 4.7.5.2 Input Files None. 4.7.5.3 Environment Variables The following environment variables shall affect the execution of chmod: LANG This variable shall determine the locale to use for the locale categories when both LC_ALL and the corresponding environment variable (beginning with LC_) do not specify a locale. See 2.6. LC_ALL This variable shall determine the locale to be used to override any values for locale categories specified by the settings of LANG or any environment variables beginning with LC_. LC_CTYPE This variable shall determine the locale for the interpretation of sequences of bytes of text data as characters (e.g., single- versus multibyte characters in arguments). LC_MESSAGES This variable shall determine the language in which messages should be written. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 396 4 Execution Environment Utilities Part 2: SHELL AND UTILITIES P1003.2/D11.2 4.7.5.4 Asynchronous Events Default. 4.7.6 External Effects 4.7.6.1 Standard Output None. 4.7.6.2 Standard Error Used only for diagnostic messages. 4.7.6.3 Output Files None. 4.7.7 Extended Description The _m_o_d_e operand shall be either a symbolic_mode expression or a nonnegative octal integer. The symbolic_mode form is described by the grammar in 4.7.7.1. Each clause shall specify an operation to be performed on the current file mode bits of each _f_i_l_e. The operations shall be performed on each _f_i_l_e in the order in which the clauses are specified. The _w_h_o symbols u, g, and o shall specify the _u_s_e_r, _g_r_o_u_p, and _o_t_h_e_r parts of the file mode bits, respectively. A _w_h_o consisting of the symbol a shall be equivalent to ugo. The _p_e_r_m symbols r, w, and x represent the _r_e_a_d, _w_r_i_t_e, and _e_x_e_c_u_t_e/_s_e_a_r_c_h portions of file mode bits, respectively. The _p_e_r_m symbol s shall represent the _s_e_t-_u_s_e_r-_I_D-_o_n-_e_x_e_c_u_t_i_o_n (when who contains or implies u) and _s_e_t-_g_r_o_u_p-_I_D-_o_n-_e_x_e_c_u_t_i_o_n (when who contains or implies g) bits. The perm symbol X shall represent the execute/search portion of the file mode bits if the file is a directory or if the current (unmodified) file mode bits have at least one of the execute bits (S_IXUSR, S_IXGRP, or S_IXOTH) set. It shall be ignored if the file is not a directory and none of the execute bits are set in the current file mode bits. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 4.7 chmod - Change file modes 397 P1003.2/D11.2 INFORMATION TECHNOLOGY--POSIX The permcopy symbols u, g, and o shall represent the current permissions associated with the user, group, and other parts of the file mode bits, respectively. For the remainder of subclause 4.7.7 up to subclause 4.7.7.1, perm refers to the nonterminals perm and permcopy in the grammar in 4.7.7.1. If multiple actionlist_s are grouped with a single wholist in the grammar, each actionlist shall be applied in the order specified with that wholist. The op symbols shall represent the operation performed, as follows: + If perm is not specified, the + operation shall not change the file mode bits. If who is not specified, the file mode bits represented by perm for the owner, group, and other permissions, except for those with corresponding bits in the file mode creation mask of the invoking process, shall be set. Otherwise, the file mode bits represented by the specified who and perm values shall be set. - If perm is not specified, the - operation shall not change the file mode bits. If who is not specified, the file mode bits represented by perm for the owner, group, and other permissions, except for those with corresponding bits in the file mode creation mask of the invoking process, shall be cleared. Otherwise, the file mode bits represented by the specified who and perm values shall be cleared. = Clear the file mode bits specified by the who value, or, if no who value is specified, all of the file mode bits specified in this standard. If perm is not specified, the = operation shall make no further modifications to the file mode bits. If who is not specified, the file mode bits represented by perm for the owner, group, and other permissions, except for those with corresponding bits in the file mode creation mask of the invoking process, shall be set. Otherwise, the file mode bits represented by the specified who and perm values shall be set. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 398 4 Execution Environment Utilities Part 2: SHELL AND UTILITIES P1003.2/D11.2 When using the symbolic mode form on a regular file, it is implementation defined whether or not: (1) Requests to set the set-user-ID-on-execution or set-group-ID- on-execution bit when all execute bits are currently clear and none are being set are ignored, (2) Requests to clear all execute bits also clear the set-user-ID- on-execution and set-group-ID-on-execution bits, or (3) Requests to clear the set-user-ID-on-execution or set-group-ID- on-execution bits when all execute bits are currently clear are ignored. However, if the command ls -l file (see 4.39.6.1) writes an s in the positions indicating that the set-user-ID- on-execution or set-group-ID-on-execution, the commands chmod u-s file or chmod g-s file, respectively, shall not be ignored. When using the symbolic mode form on other file types, it is 2 implementation defined whether or not requests to set or clear the set- 2 user-ID-on-execution or set-group-ID-on-execution bits are honored. 2 If the who symbol o is used in conjunction with the perm symbol s with no other who symbols being specified, the set-user-ID-on-execution and set- group-ID-on-execution bits shall not be modified. It shall not be an error to specify the who symbol o in conjunction with the perm symbol s. For an octal integer _m_o_d_e operand, the file mode bits shall be set absolutely. The octal number form of the _m_o_d_e operand is obsolescent. For each bit set in the octal number, the corresponding file permission 2 bit shown in the following table shall be set; all other file permission 2 bits shall be cleared. For regular files, for each bit set in the octal 2 number corresponding to the set-user-ID-on-execution or the set-group- 2 ID-on-execution bits shown in the following table shall be set; if these 2 bits are not set in the octal number, they shall be cleared. For other 2 file types, it is implementation defined whether or not requests to set 2 or clear the set-user-ID-on-execution or set-group-ID-on-execution bits 2 are honored. 2 _______________________________________________________________________ _|O_c_t_a_l___M_o_d_e__b_i_t___|_O_c_t_a_l___M_o_d_e__b_i_t___|_O_c_t_a_l___M_o_d_e__b_i_t___|_O_c_t_a_l___M_o_d_e__b_i_t__| |4000 S_ISUID | 0400 S_IRUSR | 0040 S_IRGRP | 0004 S_IROTH | _|_________________|__________________|__________________|_________________| _|2_0_0_0____S___I_S_G_I_D____|_0_2_0_0____S___I_W_U_S_R____|_0_0_2_0____S___I_W_G_R_P____|_0_0_0_2____S___I_W_O_T_H___| | | 0100 S_IXUSR | 0010 S_IXGRP | 0001 S_IXOTH | _|_________________|__________________|__________________|_________________| When bits are set in the octal number other than those listed in the table above, the behavior is unspecified. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 4.7 chmod - Change file modes 399 P1003.2/D11.2 INFORMATION TECHNOLOGY--POSIX 4.7.7.1 chmod Grammar The grammar and lexical conventions in this subclause describe the syntax for the symbolic_mode operand. The general conventions for this style of grammar are described in 2.1.2. A valid symbolic_mode can be represented as the nonterminal symbol symbolic_mode in the grammar. Any discrepancies found between this grammar and descriptions in the rest of this clause shall be resolved in favor of this grammar. The lexical processing shall be based entirely on single characters. Implementations need not allow s within the single argument being processed. %start symbolic_mode %% symbolic_mode : clause | symbolic_mode ',' clause ; clause : actionlist | wholist actionlist ; wholist : who | wholist who ; who : 'u' | 'g' | 'o' | 'a' ; actionlist : action | actionlist action ; action : op | op permlist | op permcopy ; permcopy : 'u' | 'g' | 'o' ; Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 400 4 Execution Environment Utilities