taildev-null

What is the purpose of tail -f /dev/null, usually at the end of scripts?


Before you light your torches:

However, I cannot grasp the reason for using the following:

tail -f /dev/null

This command is often found at the end of server-side scripts or, as it happened to me recently, in Docker containers (CMD ['sh', '-c', 'echo "The app is running!" && tail -f /dev/null']).
By knowing what I listed above, I would expect the output of tail to be a blank screen, forever, since no I/O to /dev/null is ever exposed to any program - trying the command in the shell does exactly that.

I can only think that this is a fancy way of Press CTRL-C to terminate.
But is there any non-obvious purpose to it other than that?
Can you achieve the same with other commands? I could think of read anyKey for the popular Press any key to continue... prompt.


Solution

  • The purpose is to not quit. It serves the same purpose as sleep infinity, but more portable when infinity is not understood by sleep.