I am trying to understand the grub config files. So, during this process I came across with file /etc/grub.d/40_custom. My file contains the following lines:
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
menuentry "Windows 10" --class windows --class os {
insmod part_msdos
savedefault
insmod ntfs
insmod ntldr
set root='(hd0,msdos1)'
ntldr ($root)/bootmgr
}
as my system is dual boot and apparently this is the boot loader for windows 10.
My question though is this part exec tail -n +3 $0
.
If I am deciphering it correctly this just means print the last lines starting from the 3rd line (+3
) of the file $0
. $0
of course in this case is the actual file /etc/grub.d/40_custom.
So, why do we use this command in 40_custom file? As I get it the output would be the same if ιt was omitted altogether. The only different I might think of is the 1st line which identifies the interpreter:
#!/bin/sh
But then again it is executed since exec tail -n +3 $0
follows it. So, is this just a (useless) convention?
#!/bin/tail -n +2
as a shellbang? Will it print rest of the file? – val - disappointed in SE Jan 07 '19 at 11:24-n +2
seems to be interpreted as-n 2
and only the last two lines are printed. That's probably worth its own question though. – terdon Jan 07 '19 at 11:35n
and the+
. In Linux at least, after the executable path and a space, the following characters are treated as a single argument. So with the space, tail sees it and probably decides to remove whatever invalid prefix-n
's argument has (in this case, a space and a+
) until it gets to the number. However, like Charles Duffy said, the current way they did this is probably more portable to other Unices. – JoL Jan 07 '19 at 18:59cat <<EOF ...EOF
there – Sergiy Kolodyazhnyy Jan 08 '19 at 03:39