You can get an electrostatic shock if you are electrically 'charged' and you touch something that is earthed, or if you're earthed and you touch something that is charged.
For example, when you walk on a vinyl floor or a nylon carpet you 'charge up' because of friction. You can earth yourself, and so get an electrostatic shock by touching a metal door handle, water pipe, or even another person.
In this slideshow the man picks up electrons as he walks over the carpet:
Here are some examples of problems associated with static:
Anti-static sprays, liquids and cloths prevent the build-up of charge by allowing it to conduct away.
Static electricity can build up in clouds. This can cause a huge spark to form between the ground and the cloud. This causes lightning – a flow of charge through the atmosphere.
Here are some examples of dangers associated with static electricity:
Refuelling aircrafts and tankers also poses a particular danger. If the fuel passing along the hose to the vehicle was allowed to build up a static charge, a resulting spark might ignite the fuel. The hoses are earthed to stop this occurring.