Rashi explains in the Joseph story as to why Egyptians found it distasteful to eat with Hebrews:
And Joseph made haste for his compassion towards his brothers had been stirred and he wanted to weep; so he entered his chamber, and wept there. And he washed his face, and came out; and he restrained himself, and said: 'Set out bread.' And they set for him by himself, and for them by themselves, for the Egyptians could not bear to eat bread with the Hebrews; for it is an abomination to the Egyptians. (Gen. 43:30-32).Rashi comments only that Onkelos gives a reason for this behavior. The Artscroll Sapirstein mentions that there are two variants of Onkelos; one of which renders the targum as "For the animal that the Egyptians worship the Hebrews eat". There are two major problems with this interpretation. First, it is not implied by the text at all. The plain rendering is simply that the Egyptians found it offensive to eat with Hebrews (Hertz takes this approach here). Such behavior would be typical of any xenophobic culture, and for millennia the people of Egypt believed themselves to be far superior to all of the surrounding nations.
The second problem is that the Egyptians themselves ate meat of animals that they worshiped (although saying that they actually worshiped animals is an oversimplification. It is more accurate to say that animals were symbolic of universal cosmic principles and manifestations of gods, rather than being worshiped as gods in their own right.) Although meat was a delicacy in ancient Egypt and was mostly eaten by nobility, even the common people would feast on domesticated animals - such as sheep and goat - during festivals. Even pork - associated with the malevolent god Set - was eaten (the Jews in Goshen would have been well aware of this, for pig was widely consumed in Lower Egypt during the New Kingdom.) Probably the most well-known animal used by the Ancient Egyptians in religious ceremony was the Apis Bull, yet the upper classes would eat cattle meat as well.
The first passage that explicitly indicates that the Egyptians had a particular abhorrence towards shepherds is found in chapter 46 after Joseph reveals himself to his brothers. He tells them that he will make especial mention of their occupation as shepherds:
And Joseph said to his brothers, and to his father's household: I will go up, and tell Pharaoh, and will say to him: 'My brothers and my father's household who were in the land of Canaan have come to me; and the men are shepherds, for they have been keepers of cattle; and they have brought their flocks, and their herds, and all that they have.' (46:31-32)Joseph then coaches them with instructions to tell Pharaoh a similar story when they are summoned before him:
And it shall come to pass, when Pharaoh shall call you, and shall say: 'What is your occupation?' then you will say 'Your servants have been keepers of cattle from our youth even until now, both we, and our forefathers'; so that you may dwell in the land of Goshen; for every shepherd is an abomination to the Egyptians. (46:33-34)There are some discrepancies between the two passages, notably the omission of the mentioning of flocks of sheep. (But more interestingly, and as an aside, note the use of "father's household" in 46:31; there were obviously other family members present besides the brothers to whom Joseph was speaking!)
Rashi now explains that shepherds are an abomination to Egyptians because sheep are a deity to them. (Why he only hinted at this earlier by referencing Onkelos I don't know.) The Sapirstein edition notes that either "abomination" is a euphemism for "pagan deity" per the Zohar, or because shepherds are considered abominable because they lack respect for the sheep, a pagan god of the Egyptians.
Returning to the text, Joseph then tells Pharaoh:
Then Joseph went in and told Pharaoh, and said: 'My father and my brothers, and their flocks, and their herds, and all that they have, have come out of the land of Canaan; and, behold, they are in the land of Goshen.' (47:1)Joseph presents five of the brothers to Pharaoh who asks them what their occupation is. They respond:
Your servants are shepherds [of sheep], both we, and our forefathers. And they said to Pharaoh: 'We have come to sojourn in the land since there is no pasture for your servants' flocks, for the famine is severe in the land of Canaan. Now therefore, we pray thee, allow your servants to dwell in the land of Goshen.' (47:3-4)To which Pharaoh responds:
And Pharaoh spoke to Joseph, saying: 'Your father and your brothers have come to you; the land of Egypt is before you - in the best of the land settle your father and your brothers; in the land of Goshen let them settle. And if you know any able men among them, then make them rulers over my livestock.' (47:5-6)Again we have a discrepancy with the implication that shepherding was an objectionable livelihood to the Egyptians. Pharaoh obviously considered this a critical enough occupation to make mention of his need for skilled sheepherders to Joseph! Many people kept sheep in Egypt, but this would have been on very small-scale since appropriate pasture land was scarce (thus the scarcity of sheepherders and the particular attraction of Goshen for the Jews.)
An additional problem with the biblical insistence on an abhorrence towards shepherds is the fact that Osiris, god of the underworld and primary deity for much of ancient Egyptian history, is often depicted carry a shepherd's crook. The linking of Pharaoh with Osiris meant that he, too, would carry a crook as a symbol of his office, as it "symbolizes his role as the shepherd of his people." (wiki). The crook was thus one of the most important items associated with Pharaoh, often used during coronation and other ceremonial occasions. (Indeed, I probably don't even need to link to a picture of King Tut's sarcophagus as the image of his golden coffin with crook and flail is likely indelibly inscribed in your memory! But here it is anyway.)
To explain the supposed dislike for shepherds, one (religious) online commentary states that perhaps this "is a consequence of the Hyksos oppression, in which case these references in Genesis would be powerful arguments for a late date for the time of the Exodus". The writer is referring to the common translation of Hyksos as "shepherd kings". (Interestingly, Hertz uses the same translation - typical of this time period - but he also assumes that the Hyksos were in power at this time and that they "inherited" the dislike of shepherds from the Egyptians.) But this is a misnomer and indeed much of the "proof" for the Torah's claim is based on a mistranslation! "The Jewish historian, Josephus, in his Contra Apionem, claims that Manetho was the first to use the Greek term, Hyksos, incorrectly translated as "shepherd-kings". Contemporary Egyptians during the Hyksos invasion designated them as hikau khausut, which meant "rulers of foreign countries", a term that originally only referred to the ruling caste of the invaders." Source.
There are many indications that the "Israel in Egypt" stories accurately describe some details of Egyptian life and culture and likely reflect a first-person experience there (as Kenneth Kitchen, James Hoffmeier, and others loudly proclaim). Certainly any multi-source document theory regarding the Torah's origins must admit to this. A trivial (but admittedly weak) example is that the author(s) of the Torah apparently knew about a "sheep god". Quite possibly this recalls Amun, one of the most important deities of ancient Egypt. Amun took on many forms, and as god of Thebes he was depicted as ram-headed. His worshipers sacrificed a ram once a year at which time its fleece would be used as clothing for a ram-headed idol. Another Egyptian ram-headed god was Banebdjed, associated with Osiris (see above), who wore a crown with ram's horns.
Yet it does seem that there is some confused narrative as well, as witnessed by the descriptions of the Egyptian attitudes towards shepherds and the implied abhorrence towards eating meat from animals that worshiped. Perhaps one could make the argument that there was a different set of rules for foreigners regarding the latter, but I have never seen such a reference in any other historical document. Someone with greater knowledge in ancient Egyptian culture and/or archaeology is welcome to convince me otherwise.