I don't understand Digital Signature
bob hashes his message and encrypt it with alice public key

No, Bob would sign it with his own private key.  For some signature methods, this is roughly similar to &quot;encrypting with the private key&quot;, however for other signature methods, it's not; hence it is safer to keep a strong distinction between 'signing' and 'encrypting'

alice receives the original message and the signature she decrypts the signature with her private key and she compares the original message with the signature

No, Alice would validate the signature with Bob's public key.  How Alice gets a verified copy of Bob's public key is an important part of this process, however that is generally considered something to be solved by the whatever mechanism is using the signature method.

Why did we call it digital signature if an attacker can pretend to be bob?

If the attacker does not have Bob's private key (and so he cannot generate sigantures that would verify with Bob's public key), and he can't fool Alice into using the attack's public key, the attacker cannot pretend to be Bob.