2

I am trying to revert a file from a previous version of the same file, using diff and patch

diff_out=$(diff -u $name $chVer/$name.latest) patch -u $name $diff_out 

Where $name is the file name i want to revert, $chVer is the folder of all the older versions of the file

Unfortunately this doesn't work

patch: unrecognized option '---' patch: Try 'patch --help' for more information. 

the $diff_out content is not read by the patch command as a file, thus do i need the output the content of the diff to a temporary file that i read with patch ? I wanted not to do that, because i will delete that file as soon as the patch is done

3
  • 1
    Why not just copy the old file over? Commented Mar 2, 2018 at 14:05
  • Quote your parameter expansions, and see if you still have a problem. Commented Mar 2, 2018 at 14:24
  • cat $chVer/$name.latest > $name Commented Mar 2, 2018 at 21:13

2 Answers 2

1

Try $diff_out | patch -u $name

patch will accept a diff from stdin if not provided as an argument.

Sign up to request clarification or add additional context in comments.

1 Comment

This answers the question of "how to patch a file with a temporary diff file". If the answer should be improved or is incorrect, please comment.
0

You can avoid the temporary file by using process substitution:

patch -u $name <(diff -u $name $chVer/$name.latest) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.