Be smart when hanging shelves. Shown in this photo is a job where it turned out homeowner installed new pantry shelves, and anchored them into his drain pipe to the second floor. Looking in the basement and measuring to make sure there are no pipes in the wall you are working on can be all it takes. If those steps are taken it will make hitting a pipe less likely. Using a stud finder and locating studs can determine wall construction lay out also and can help with this. But all things said it can still happen. Try to locate if possible from the basement or use common sense if you know there is a bathroom over head there is likely to be pipes in the wall below. Just a helpful reminder from your local plumber close to you.