I don't understand Digital Signature Why did we call it digital signature if an attacker can pretend to be Bob?
Bob hashes his message, encrypts the hash with Alice's public key, and sends it to Alice with the original message. Alice receives that message and the signature. She decrypts the signature with her private key, and compares the outcome with the hash of the message.
But why did we call it a signature if a hacker can do what Bob has done?
A hacker can also hash his message, encrypt the hash with Alice's public key and send it to Alice. Sorry guys but digital signature seems similar to asymmetric encryption to me, a hacker can also pretend to be Bob.
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.