You can survive a shark attack by staying still.
Trying to swim away won’t help in this situation. The correct behavior here will be to slowly move away from the shark’s path, and stay calm. Keep an eye on the shark. When it has passed by you, try to find a way out of the water. However, if you can’t and have to defend yourself, hit it on its gills, eyes, or the tip of its nose.