To install shelves with no visible means of support on both masonry and sheetrock walls, carefully drill holes for very long 1/2″ hex head bolts, then screw the bolts into the wall. Cut the heads of the bolt off, and use a square, short level and a hammer to make sure that these long pins are level and square to the wall. Then 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.