Today I ran into some code that's writing a newline character explicitly into a sysctl file. See moby/docker source code. My first thought is that the author has diligently copied the shell's behaviour into go despite the newline being redundant.
But then I started to look for documentation on the subject and found it a really hard one to find information on either way. I haven't managed to come up with anything so far.
When writing sysctl files in
/proc/sys/ many of the values are integers written in ASCII. For example, to toggle something on or off you have to write
0 as text into a file.
Often the advice here on U&L and on blogs etc. is to do this in the shell using
echo. For example turning on IPv4 forwarding:
echo 1 > /proc/sys/net/ipv4/ip_forward
But this advice does something subtly different to its stated goal. It doesn't write a single byte 0x31 to the file. It writes two: 0x31 0x0A also known as
1\n. I had always assumed the newline (0x0A) was simply ignored by the kernel.
Does writing a newline character into a sysctl file (eg
/proc/sys/net/ipv4/ip_forward) have any effect? References welcome even if they are links to source code.