This particular quote is not a direct quote from Shakespeare. The word "nightmare" only appears once in Shakespeare's plays and it is not in a context anything like this quote. (This is according to a couple of sites where you can search all of Shakespeare's works at once.)
I think that you may be thinking of a famous line that is from Shakespeare and has a somewhat similar meaning. It is from Hamlet's "to be or not to be" soliloquy in Act III, Scene 1 of Hamlet. In that passage, Hamlet says
To sleep- perchance to dream: ay, there's the rub!
For in that sleep of death what dreams may come
When we have shuffled off this mortal coil
That sort of means the same thing -- if you dream, you may have nightmares.
Get Ahead with eNotes
Start your 48-hour free trial to access everything you need to rise to the top of the class. Enjoy expert answers and study guides ad-free and take your learning to the next level.
Already a member? Log in here.