I carefully drill holes for very long 1/2″ hex head bolts, then screw the bolts into the wall. The heads are cut off, and I use a square and a hammer to make sure that these long pins are level and square to the wall. Then I drill holes in the back of the shelf board such that the pins will line up into the back of the board.
Using a hammer and another board so that I don’t dent the shelves, I pound the shelf board on to the wall pins. The pressure of the pins on the sides of the holes holds the shelf firmly to the wall.