\override
command every time a property has to be changed.
In this example, all needed commands have been put in a Scheme music function. Therefore, you can use it as a shortcut, at any time, to print the bar number. If you want to print the bar number in several bars, you can enclose the relevant section in braces {...}
so that the function applies to every bars in it.