Master
Master

Reputation: 71

Avoiding patch command to ask for 'File to patch:'

I am trying to patch a file.

The patch file is in the directory in which the list of files to be patched.

When I run commend

patch < file.patch

It prompts me

File to patch:

How to avoid this? What should I add in the patch file to automatically detect the filename that it should patch

Upvotes: 7

Views: 9094

Answers (2)

h0tw1r3
h0tw1r3

Reputation: 6818

GNU version of patch includes a --batch or -t option, which prevents all prompting.

-t or --batch
   Suppress  questions  like  -f, but make some different assumptions: skip patches
   whose headers do not contain file names (the same as -f); skip patches for which
   the file has the wrong version for the  Prereq: line in the patch; and assume
   that patches are reversed if they look like they are.

Upvotes: 4

3442
3442

Reputation: 8576

When creating the patch with diff, the output format, by default, does not includes the filename of the original filename. You can change this with the -u option like this...

$ diff -u OriginalFile NewFile >NewFile.patch

Then, you can simply...

$ patch -u <NewFile.patch

For further information, read about the unified GNU diff format.

Upvotes: 1

Related Questions