Paradoxically, if your opponent has a gun, you might be safer unarmed than if armed merely with a knife. If you pull out the knife, you'll be shot for sure, as the opponent feels immediately threatened. If you're unarmed, depending on what his motives are, he might leave you alone after robbing you. The answer is either to carry a gun yourself, or avoid these kinds of situations entirely. Carrying a knife for defensive purposes is just a bad idea. If, by some chance, the bad guy also has a knife (but no gun), he's likely to be far more experienced in this sort of thing than you are. So you lose either way.