I created the script ~/kernel.sh and pasted the suggested content. I then give it executable permissions and run it with sudo ~/kernel.sh.
It gives this error
Errore:
Problema: The operation would result in removing the following protected packages: kernel-core
(try to add '--skip-broken' to skip uninstallable packages)
Failed to remove old kernels
I am a bit frightened 'cause my understanding is that the script would try to deleted a wrong kernel.
With fedora it is totally unnecessary to remove older kernels. Fedora does that automatically and by default keeps the latest 3 kernels installed in case of a boot problem. Thus that script is normally not needed. Note also that the link you followed is for power users – as shown by the note at the very top.
If you run the command dnf list installed 'kernel*' you should see each kernel package listed with the latest 3 versions (with a couple exceptions having only one version). Any differences would normally be because the user chose to keep more or had not upgraded enough times to perform at least 2 kernel updates after the initial install.
Most users never need to do anything more than the dnf upgrade and the system manages the rest for them.
I don’t use kde, but I do always update using dnf. It has never been necessary to do the additional that is given in that link. The normal dnf upgrade process manages all that I have ever needed for many years.