logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

cmp.1p (8971B)


  1. '\" et
  2. .TH CMP "1P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. cmp
  12. \(em compare two files
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. cmp \fB[\fR-l|-s\fB] \fIfile1 file2\fR
  17. .fi
  18. .SH DESCRIPTION
  19. The
  20. .IR cmp
  21. utility shall compare two files. The
  22. .IR cmp
  23. utility shall write no output if the files are the same. Under default
  24. options, if they differ, it shall write to standard output the byte and
  25. line number at which the first difference occurred. Bytes and lines
  26. shall be numbered beginning with 1.
  27. .SH OPTIONS
  28. The
  29. .IR cmp
  30. utility shall conform to the Base Definitions volume of POSIX.1\(hy2017,
  31. .IR "Section 12.2" ", " "Utility Syntax Guidelines".
  32. .P
  33. The following options shall be supported:
  34. .IP "\fB\-l\fP" 10
  35. (Lowercase ell.) Write the byte number (decimal) and the differing
  36. bytes (octal) for each difference.
  37. .IP "\fB\-s\fP" 10
  38. Write nothing to standard output or standard error when files
  39. differ; indicate differing files through exit status only.
  40. It is unspecified whether a diagnostic message is written to
  41. standard error when an error is encountered; if a message is
  42. not written, the error is indicated through exit status only.
  43. .SH OPERANDS
  44. The following operands shall be supported:
  45. .IP "\fIfile1\fR" 10
  46. A pathname of the first file to be compared. If
  47. .IR file1
  48. is
  49. .BR '\-' ,
  50. the standard input shall be used.
  51. .IP "\fIfile2\fR" 10
  52. A pathname of the second file to be compared. If
  53. .IR file2
  54. is
  55. .BR '\-' ,
  56. the standard input shall be used.
  57. .P
  58. If both
  59. .IR file1
  60. and
  61. .IR file2
  62. refer to standard input or refer to the same FIFO special, block
  63. special, or character special file, the results are undefined.
  64. .SH STDIN
  65. The standard input shall be used only if the
  66. .IR file1
  67. or
  68. .IR file2
  69. operand refers to standard input. See the INPUT FILES section.
  70. .SH "INPUT FILES"
  71. The input files can be any file type.
  72. .SH "ENVIRONMENT VARIABLES"
  73. The following environment variables shall affect the execution of
  74. .IR cmp :
  75. .IP "\fILANG\fP" 10
  76. Provide a default value for the internationalization variables that are
  77. unset or null. (See the Base Definitions volume of POSIX.1\(hy2017,
  78. .IR "Section 8.2" ", " "Internationalization Variables"
  79. for the precedence of internationalization variables used to determine
  80. the values of locale categories.)
  81. .IP "\fILC_ALL\fP" 10
  82. If set to a non-empty string value, override the values of all the
  83. other internationalization variables.
  84. .IP "\fILC_CTYPE\fP" 10
  85. Determine the locale for the interpretation of sequences of bytes of
  86. text data as characters (for example, single-byte as opposed to
  87. multi-byte characters in arguments).
  88. .IP "\fILC_MESSAGES\fP" 10
  89. .br
  90. Determine the locale that should be used to affect the format and
  91. contents of diagnostic messages written to standard error and
  92. informative messages written to standard output.
  93. .IP "\fINLSPATH\fP" 10
  94. Determine the location of message catalogs for the processing of
  95. .IR LC_MESSAGES .
  96. .SH "ASYNCHRONOUS EVENTS"
  97. Default.
  98. .SH STDOUT
  99. In the POSIX locale, results of the comparison shall be written to
  100. standard output. When no options are used, the format shall be:
  101. .sp
  102. .RS 4
  103. .nf
  104. "%s %s differ: char %d, line %d\en", \fIfile1\fR, \fIfile2\fR,
  105. <\fIbyte number\fR>, <\fIline number\fR>
  106. .fi
  107. .P
  108. .RE
  109. .P
  110. When the
  111. .BR \-l
  112. option is used, the format shall be:
  113. .sp
  114. .RS 4
  115. .nf
  116. "%d %o %o\en", <\fIbyte number\fR>, <\fIdiffering byte\fR>,
  117. <\fIdiffering byte\fR>
  118. .fi
  119. .P
  120. .RE
  121. .P
  122. for each byte that differs. The first <\fIdiffering\ byte\fP> number is
  123. from
  124. .IR file1
  125. while the second is from
  126. .IR file2 .
  127. In both cases, <\fIbyte\ number\fP> shall be relative to the beginning
  128. of the file, beginning with 1.
  129. .P
  130. No output shall be written to standard output when the
  131. .BR \-s
  132. option is used.
  133. .SH STDERR
  134. The standard error shall be used only for diagnostic messages. If the
  135. .BR \-l
  136. option is used and
  137. .IR file1
  138. and
  139. .IR file2
  140. differ in length, or if the
  141. .BR \-s
  142. option is not used and
  143. .IR file1
  144. and
  145. .IR file2
  146. are identical for the entire length of the shorter file, in the POSIX
  147. locale the following diagnostic message shall be written:
  148. .sp
  149. .RS 4
  150. .nf
  151. "cmp: EOF on %s%s\en", <\fIname of shorter file\fR>, <\fIadditional info\fR>
  152. .fi
  153. .P
  154. .RE
  155. .P
  156. The <\fIadditional\ info\fP> field shall either be null or a string
  157. that starts with a
  158. <blank>
  159. and contains no
  160. <newline>
  161. characters. Some implementations report on the number of lines in
  162. this case.
  163. .P
  164. If the
  165. .BR \-s
  166. option is used and an error occurs, it is unspecified whether a
  167. diagnostic message is written to standard error.
  168. .SH "OUTPUT FILES"
  169. None.
  170. .SH "EXTENDED DESCRIPTION"
  171. None.
  172. .SH "EXIT STATUS"
  173. The following exit values shall be returned:
  174. .IP "\00" 6
  175. The files are identical.
  176. .IP "\01" 6
  177. The files are different; this includes the case where one file is
  178. identical to the first part of the other.
  179. .IP >1 6
  180. An error occurred.
  181. .SH "CONSEQUENCES OF ERRORS"
  182. Default.
  183. .LP
  184. .IR "The following sections are informative."
  185. .SH "APPLICATION USAGE"
  186. Although input files to
  187. .IR cmp
  188. can be any type, the results might not be what would be expected on
  189. character special device files or on file types not described by the
  190. System Interfaces volume of POSIX.1\(hy2017. Since this volume of POSIX.1\(hy2017 does not specify the block size used when doing
  191. input, comparisons of character special files need not compare all of
  192. the data in those files.
  193. .P
  194. For files which are not text files, line numbers simply reflect the
  195. presence of a
  196. <newline>,
  197. without any implication that the file is organized into lines.
  198. .P
  199. Since the behavior of
  200. .BR \-s
  201. differs between implementations as to whether error messages are
  202. written, the only way to ensure consistent behavior of
  203. .IR cmp
  204. when
  205. .BR \-s
  206. is used is to redirect standard error to
  207. .BR /dev/null .
  208. .P
  209. If error messages are wanted, instead of using
  210. .BR \-s
  211. standard output should be redirected to
  212. .BR /dev/null ,
  213. and anything written to standard error should be discarded if the exit
  214. status is 1. For example:
  215. .sp
  216. .RS 4
  217. .nf
  218. silent_cmp() {
  219. # compare files with no output except error messages
  220. message=$(cmp "$@" 2>&1 >/dev/null)
  221. status=$?
  222. case $status in
  223. (0|1) ;;
  224. (*) printf \(aq%s\en\(aq "$message" ;;
  225. esac
  226. return $status
  227. }
  228. .fi
  229. .P
  230. .RE
  231. .SH EXAMPLES
  232. None.
  233. .SH RATIONALE
  234. The global language in
  235. .IR "Section 1.4" ", " "Utility Description Defaults"
  236. indicates that using two mutually-exclusive options together produces
  237. unspecified results. Some System V implementations consider the option
  238. usage:
  239. .sp
  240. .RS 4
  241. .nf
  242. cmp -l -s ...
  243. .fi
  244. .P
  245. .RE
  246. .P
  247. to be an error. They also treat:
  248. .sp
  249. .RS 4
  250. .nf
  251. cmp -s -l ...
  252. .fi
  253. .P
  254. .RE
  255. .P
  256. as if no options were specified. Both of these behaviors are
  257. considered bugs, but are allowed.
  258. .P
  259. The word
  260. .BR char
  261. in the standard output format comes from historical usage, even though
  262. it is actually a byte number. When
  263. .IR cmp
  264. is supported in other locales, implementations are encouraged to use
  265. the word
  266. .IR byte
  267. or its equivalent in another language. Users should not interpret this
  268. difference to indicate that the functionality of the utility changed
  269. between locales.
  270. .P
  271. Some implementations report on the number of lines in the
  272. identical-but-shorter file case. This is allowed by the inclusion of
  273. the <\fIadditional\ info\fP> fields in the output format. The
  274. restriction on having a leading
  275. <blank>
  276. and no
  277. <newline>
  278. characters is to make parsing for the filename easier. It is recognized
  279. that some filenames containing white-space characters make parsing
  280. difficult anyway, but the restriction does aid programs used on systems
  281. where the names are predominantly well behaved.
  282. .SH "FUTURE DIRECTIONS"
  283. Future versions of this standard may require that diagnostic messages
  284. are written to standard error when the
  285. .BR \-s
  286. option is specified.
  287. .SH "SEE ALSO"
  288. .IR "\fIcomm\fR\^",
  289. .IR "\fIdiff\fR\^"
  290. .P
  291. The Base Definitions volume of POSIX.1\(hy2017,
  292. .IR "Chapter 8" ", " "Environment Variables",
  293. .IR "Section 12.2" ", " "Utility Syntax Guidelines"
  294. .\"
  295. .SH COPYRIGHT
  296. Portions of this text are reprinted and reproduced in electronic form
  297. from IEEE Std 1003.1-2017, Standard for Information Technology
  298. -- Portable Operating System Interface (POSIX), The Open Group Base
  299. Specifications Issue 7, 2018 Edition,
  300. Copyright (C) 2018 by the Institute of
  301. Electrical and Electronics Engineers, Inc and The Open Group.
  302. In the event of any discrepancy between this version and the original IEEE and
  303. The Open Group Standard, the original IEEE and The Open Group Standard
  304. is the referee document. The original Standard can be obtained online at
  305. http://www.opengroup.org/unix/online.html .
  306. .PP
  307. Any typographical or formatting errors that appear
  308. in this page are most likely
  309. to have been introduced during the conversion of the source files to
  310. man page format. To report such errors, see
  311. https://www.kernel.org/doc/man-pages/reporting_bugs.html .