Infectious diseases can be spread many ways. While having someone sneeze or cough on you is an obvious problem, what you may not know is that shaking hands with someone who has an infectious disease can transmit the disease to you as well. That person may cover their mouth or nose when sneezing. When they later shake your hand they may then be spreading that infection to you through the handshake.
You then infect yourself by rubbing your eyes, nose or mouth. So it's always a good idea to wash your hands after this kind of contact, especially if the well-wisher has a cough or cold. In fact, the Centers For Disease Control and prevention say that hand washing is the number one way to prevent the spread of contagious diseases.