Two of the essential tools in software development are Patch y Diff. It is not a mystery how they work, but I think this will be an interesting post. 🙂
Both are very powerful, and this is just like touching the surface, they have more utilities and other functions. Basically with these two tools we can create version control,
Diff
We refer to comparison, it compares an "original" file with the "new" one, and informs us of the differences that exist between them. This tool also allows us to create .patch files that we use to create patches for our programs.
Patch
It is the command with which we literally "patch" our original file, adding and / or removing lines according to the instructions contained in the .patch file
There is also vimdiff, which is a visual tool to apply patches without the need for a .patch file, since it compares "original" and "new" and on the same file it is possible to edit line by line or the entire document. This I won't explain but I think it deserves a mention.
Example
Now the fun is. Example!
This is the case, we have a great script that asks for your name and your age, if you are over 18 it tells you that you can vote, otherwise it tells you that you cannot vote.
original.sh
#! / bin / bash echo "Enter your name:" read name echo "Enter your age:" read age if [[18 -lt $ age]] then echo "Hello $ name, you are $ old and you can vote!" else echo "Hello $ name, you are $ old and cannot vote ..." fi
Done, here is the running script:
So, as good users we are, we share our script with a friend :), but we get a message saying that it has a flaw, that when it is 18 it says that it cannot vote when it should.
Now we begin to correct the small error and make a few modifications ...
new.sh
#! / bin / bash maxAge = 18 echo "Enter your name:"; read name echo "Write your age:"; read age if [[$ maxAge -le $ age]]; then echo "Hello $ name, you are $ years old and you can vote!" else echo "Hello $ name, you are $ years old and you cannot vote ..." fi exit 0
Suppose the script is very heavy. So, in order not to send the whole script again, we create a .patch 😀
$ diff -u original.sh new.sh> patch.patch
And now we have our patch. Here's a view on Vim:
And to apply it we simply use the .patch file in the script to be patched. Here is called originalAmigo.sh, which is an exact copy of the script original.sh
$ patch originalFriend.sh <patch.patch
And this leaves us our file originalAmigo.sh So:
As you can see it is very easy to get the diffs and apply the patches. It's all from me.
Greetings people, we will read next Friday.
Great, thank you very much 🙂
If you want some color, please use colordiff ^ __ ^
Now I understand how patches work in Debian.
Hello, I know that system notifications can be shown with notify-send from the console, but what I would like to do is to be able to schedule what time or how long to show me a notification, is there any way to do it? I use elementary, which is based on Ubuntu 12.04, in case it helps, thanks
Well, it can be done using the system cron 😉
and how can that be done? I just learned how to use the notify-send command
You can search for cron here in the blog there are many posts about it 🙂
Very good, thank you!
I always use this to update the kernel, I download only the patches and apply to the sources, so I don't have to download 80mb each release.