Can an md who is not an ophthalmologist write a prescription for getting eyeglasses?

Not appropriate. If you needed such a note to get reading glasses you can pick out by yourself at a kiosk,it would be fine. Having them covered by your HSA can be a hassle. Beyond that it would not be appropriate. Your doc would not have the proper equipment to properly assess your eyes for glasses. The state medical boards expect docs to practice within the areas they train and discipline those who don't.
Yes, but... ... It would be similar to an eye doctor writing for an orthotic device for a leg. During medical school, students receive only basic training in the different medical specialties. After graduation, doctors receive their specialized knowledge in residency programs. Without the proper knowledge, training and equipment, a non- eye doctor will not be able to write a proper prescription for glasses.
Technically, yes. It probably could be done and accepted by optical shops, but an md who is not an ophthalmologist to prescribe glasses would be foolish as there is a high-degree of training involved in knowing how to prescribe glasses. I am unaware of any laws that would be broken, however, in doing so.
Yes. It can be written by an optometrist . An Optometrist is not an Ophthalmologist but can prescribe eyeglasses .
Eyeglasses . An eyeglasses prescription can only be written by an eye care professional such as an optometrist or ophthalmologist.