This expression is found in Persia and Egypt at least. In the days when Medicine Men were more common, students were tutored in the Black Arts. They were compelled to run through a subterranean hall with the devil after them. If they ran so fast that the devil could only catch their shadow, or part of it, they became first-rate magicians, but they would lose either all or part of their shadow. Therefore, the expression means, "May you escape wholly and entirely from the clutches of the foul fiend."
It is the Moslem form of 'thank you'. The expression has been 'adopted' by beggars, who looks upon someone giving alms as the channel through which Allah sends him what he wants, and he prays for more to come. So, “May your shadow never be less” for the beggar means, 'may you increase in prosperity so that I may gain thereby!'
Student or Learner