Sharks rarely attack humans unlike as depicted in some movies which portrayed Sharks as "man-eaters". They don't usually target humans as prey. They have great eye sight and they don't usually mistake humans with their prey.
Most of the attacks on humans by sharks are due to mistaken identities and just to test what kind of "object" it is. Many times, a shark mistakes a surfer to a seal and attacks from below.
But if the shark is attacking, willingly or by mistake, one should follow a few steps to ensure lesser chances of being attacked.
The necessary steps one should take when a shark is approaching are
One has to remain calm if a shark is approaching them. Even if you try to get out of the water by swimming fast, you can not swim faster than the shark as it swims faster and as it is huge. So, there is no way you can escape from it if it really wants to attack you. You have to keep calm and watch it's movements to decide what you have to do. A shark attacks one if they feel or show any traces of fear. The slightest gesture of fear you show provokes it to attack.
You have to keep your eye on the shark. It may turn around from you but if you show any signs of movement it may turn at you. It is better to wait and watch what it does. If you get a chance to escape, try to do it fast by keeping an eye on the shark.
If there is no way you can escape from the shark, try to avoid being in the direction in which it is easy for it to attack you. If you are diving, try to find a rock or reef so that you can avoid the shark from attacking from back.
Many say that acting dead stops the shark from attacking you. It is not true in the case of an aggressive shark and it attacks the person anyways, though it won't eat. The best thing you can do if the shark is attacking you and you don't have any option is to act brave and showcase a strong defense. It may provoke the shark to back out from attacking.
How many steps you take to escape from the shark, you can not feel safe until you are out of water. Take any or all the chances of getting out of the water.
If all the cases fail and if you get attacked by the shark, try to get medical help at the earliest. After a shark bite blood loss occurs in massive amounts. Take every precaution to stop the bleeding before the doctor comes to your rescue.
Great read Sri.