📄 patch.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>patch</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="patch"></a> <a name="tag_04_98"></a><!-- patch --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_04_98_01"></a>NAME</h4><blockquote>patch - apply changes to files</blockquote><h4><a name="tag_04_98_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('UP')">UP</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> patch</tt> <b>[</b><tt>-blNR</tt><b>][</b> <tt>-c| -e| -n</tt><b>][</b><tt>-d</tt><i>dir</i><b>][</b><tt>-D</tt> <i>define</i><b>][</b><tt>-i</tt> <i>patchfile</i><b>]<br></b> <tt> </tt> <b>[</b><tt>-o</tt> <i>outfile</i><b>][</b><tt>-p</tt><i>num</i><b>][</b><tt>-r</tt> <i>rejectfile</i><b>][</b><i>file</i><b>]</b><tt><img src="../images/opt-end.gif" alt="[Option End]"border="0"></tt></code></div></blockquote><h4><a name="tag_04_98_03"></a>DESCRIPTION</h4><blockquote><p>The <i>patch</i> utility shall read a source (patch) file containing any of the three forms of difference (diff) listingsproduced by the <a href="../utilities/diff.html"><i>diff</i></a> utility (normal, context, or in the style of <a href="../utilities/ed.html"><i>ed</i></a>) and apply those differences to a file. By default, <i>patch</i> shall read from the standardinput.</p><p>The <i>patch</i> utility shall attempt to determine the type of the <a href="../utilities/diff.html"><i>diff</i></a> listing,unless overruled by a <b>-c</b>, <b>-e</b>, or <b>-n</b> option.</p><p>If the patch file contains more than one patch, <i>patch</i> shall attempt to apply each of them as if they came from separatepatch files. (In this case, the application shall ensure that the name of the patch file is determinable for each <a href="../utilities/diff.html"><i>diff</i></a> listing.)</p></blockquote><h4><a name="tag_04_98_04"></a>OPTIONS</h4><blockquote><p>The <i>patch</i> utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap12.html#tag_12_02">Section 12.2, Utility Syntax Guidelines</a>.</p><p>The following options shall be supported:</p><dl compact><dt><b>-b</b></dt><dd>Save a copy of the original contents of each modified file, before the differences are applied, in a file of the same name withthe suffix <b>.orig</b> appended to it. If the file already exists, it shall be overwritten; if multiple patches are applied to thesame file, the <b>.orig</b> file shall be written only for the first patch. When the <b>-o</b> <i>outfile</i> option is alsospecified, <i>file</i> <b>.orig</b> shall not be created but, if <i>outfile</i> already exists, <i>outfile</i> <b>.orig</b> shallbe created.</dd><dt><b>-c</b></dt><dd>Interpret the patch file as a context difference (the output of the utility <a href="../utilities/diff.html"><i>diff</i></a>when the <b>-c</b> or <b>-C</b> options are specified).</dd><dt><b>-d </b> <i>dir</i></dt><dd>Change the current directory to <i>dir</i> before processing as described in the EXTENDED DESCRIPTION section.</dd><dt><b>-D </b> <i>define</i></dt><dd>Mark changes with one of the following C preprocessor constructs: <pre><tt>#ifdef define...#endif<br>#ifndef define...#endif</tt></pre><p>optionally combined with the C preprocessor construct <b>#else</b>. If the patched file is processed with the C preprocessor,where the macro <i>define</i> is defined, the output shall contain the changes from the patch file; otherwise, the output shall notcontain the patches specified in the patch file.</p></dd><dt><b>-e</b></dt><dd>Interpret the patch file as an <a href="../utilities/ed.html"><i>ed</i></a> script, rather than a <a href="../utilities/diff.html"><i>diff</i></a> script.</dd><dt><b>-i </b> <i>patchfile</i></dt><dd>Read the patch information from the file named by the pathname <i>patchfile</i>, rather than the standard input.</dd><dt><b>-l</b></dt><dd>(The letter ell.) Cause any sequence of <blank>s in the difference script to match any sequence of <blank>s in theinput file. Other characters shall be matched exactly.</dd><dt><b>-n</b></dt><dd>Interpret the script as a normal difference.</dd><dt><b>-N</b></dt><dd>Ignore patches where the differences have already been applied to the file; by default, already-applied patches shall berejected.</dd><dt><b>-o </b> <i>outfile</i></dt><dd>Instead of modifying the files (specified by the <i>file</i> operand or the difference listings) directly, write a copy of thefile referenced by each patch, with the appropriate differences applied, to <i>outfile</i>. Multiple patches for a single fileshall be applied to the intermediate versions of the file created by any previous patches, and shall result in multiple,concatenated versions of the file being written to <i>outfile</i>.</dd><dt><b>-p </b> <i>num</i></dt><dd>For all pathnames in the patch file that indicate the names of files to be patched, delete <i>num</i> pathname components fromthe beginning of each pathname. If the pathname in the patch file is absolute, any leading slashes shall be considered the firstcomponent (that is, <b>-p 1</b> shall remove the leading slashes). Specifying <b>-p 0</b> shall cause the full pathnameto be used. If <b>-p</b> is not specified, only the basename (the final pathname component) shall be used.</dd><dt><b>-R</b></dt><dd>Reverse the sense of the patch script; that is, assume that the difference script was created from the new version to the oldversion. The <b>-R</b> option cannot be used with <a href="../utilities/ed.html"><i>ed</i></a> scripts. The <i>patch</i> utilityshall attempt to reverse each portion of the script before applying it. Rejected differences shall be saved in swapped format. Ifthis option is not specified, and until a portion of the patch file is successfully applied, <i>patch</i> attempts to apply eachportion in its reversed sense as well as in its normal sense. If the attempt is successful, the user shall be prompted to determinewhether the <b>-R</b> option should be set.</dd><dt><b>-r </b> <i>rejectfile</i></dt><dd>Override the default reject filename. In the default case, the reject file shall have the same name as the output file, withthe suffix <b>.rej</b> appended to it; see <a href="#tag_04_98_13_03">Patch Application</a> .</dd></dl></blockquote><h4><a name="tag_04_98_05"></a>OPERANDS</h4><blockquote><p>The following operand shall be supported:</p><dl compact><dt><i>file</i></dt><dd>A pathname of a file to patch.</dd></dl></blockquote><h4><a name="tag_04_98_06"></a>STDIN</h4><blockquote><p>See the INPUT FILES section.</p></blockquote><h4><a name="tag_04_98_07"></a>INPUT FILES</h4><blockquote><p>Input files shall be text files.</p></blockquote><h4><a name="tag_04_98_08"></a>ENVIRONMENT VARIABLES</h4><blockquote><p>The following environment variables shall affect the execution of <i>patch</i>:</p><dl compact><dt><i>LANG</i></dt><dd>Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume ofIEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> forthe precedence of internationalization variables used to determine the values of locale categories.)</dd><dt><i>LC_ALL</i></dt><dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd><dt><i>LC_CTYPE</i></dt><dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte asopposed to multi-byte characters in arguments and input files).</dd><dt><i>LC_MESSAGES</i></dt><dd>Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error andinformative messages written to standard output.</dd><dt><i>NLSPATH</i></dt><dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Determine the location of message catalogs for the processing of <i>LC_MESSAGES .</i> <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd><dt><i>LC_TIME</i></dt><dd>Determine the locale for recognizing the format of file timestamps written by the <a href="../utilities/diff.html"><i>diff</i></a> utility in a context-difference input file.</dd></dl></blockquote><h4><a name="tag_04_98_09"></a>ASYNCHRONOUS EVENTS</h4><blockquote><p>Default.</p></blockquote><h4><a name="tag_04_98_10"></a>STDOUT</h4><blockquote><p>Not used.</p></blockquote><h4><a name="tag_04_98_11"></a>STDERR</h4><blockquote><p>The standard error shall be used for diagnostic and informational messages.</p></blockquote><h4><a name="tag_04_98_12"></a>OUTPUT FILES</h4><blockquote><p>The output of the <i>patch</i> utility, the save files ( <b>.orig</b> suffixes), and the reject files ( <b>.rej</b> suffixes)shall be text files.</p></blockquote><h4><a name="tag_04_98_13"></a>EXTENDED DESCRIPTION</h4><blockquote><p>A patch file may contain patching instructions for more than one file; filenames shall be determined as specified in <a href="#tag_04_98_13_02">Filename Determination</a> . When the <b>-b</b> option is specified, for each patched file, the original shallbe saved in a file of the same name with the suffix <b>.orig</b> appended to it.</p><p>For each patched file, a reject file may also be created as noted in <a href="#tag_04_98_13_03">Patch Application</a> . In theabsence of a <b>-r</b> option, the name of this file shall be formed by appending the suffix <b>.rej</b> to the originalfilename.</p><h5><a name="tag_04_98_13_01"></a>Patch File Format</h5><p>The patch file shall contain zero or more lines of header information followed by one or more patches. Each patch shall containzero or more lines of filename identification in the format produced by <a href="../utilities/diff.html"><i>diff</i></a> <b>-c</b>,and one or more sets of <a href="../utilities/diff.html"><i>diff</i></a> output, which are customarily called <i>hunks</i>.</p><p>The <i>patch</i> utility shall recognize the following expression in the header information:</p><dl compact><dt><b>Index: </b> <i>pathname</i></dt><dd><br>The file to be patched is named <i>pathname</i>.</dd></dl><p>If all lines (including headers) within a patch begin with the same leading sequence of <blank>s, the <i>patch</i> utilityshall remove this sequence before proceeding. Within each patch, if the type of difference is context, the <i>patch</i> utilityshall recognize the following expressions:</p><dl compact><dt>*** <i>filename timestamp</i></dt><dd><br>The patches arose from <i>filename</i>.</dd>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -