Mythbusters did a fun episode of knife vs gun in a close fight.
If memory serves:
If you attack a shooter from 10' away:
If he is ready, you will get there, but get shot.
If he is not ready, you can actually win that fight.
Getting close enough to be able to do anything without getting shot is the hardest part.
The unfortunate reality is that you probably have to settle for not dying, rather than not getting shot. You don’t have to win. You just have to not lose.
People say knife can beat gun if within 21’ and gun still has to be drawn. I could see mythbuster’s 10’ if the person is ready.
Those distances are for untrained people. Some types of kung fu specifically train gap closing ability, so that can give an extra advantage.