If social fear keeps me from doing something wrong, is it good? A great personality has said that if you do something out of fear, it does not have any value. But there is another idea that if something makes you do good deeds or prevents you from doing wrong, the nature of the thing does not matter as what matters is what you do not what you think and if you do good it is bound to do good to yourself.
—Gaurav Sharma, India
Paramhansa Yogananda used to say, “It is better to do the right thing for the wrong reason, than not to do the right thing at all.” This, I think, answers your question.
The important point is to do the best you can in all circumstances. If a not-so-noble reason is the best motivator you can manage for avoiding wrong action, well, at least you are avoiding wrong action, and that is a good thing. But do ask God to help you find the nobler reasons in the future, because not only will you feel better about it, but you will also be more clearly attuned to dharma—and dharma is a precious lifeline to freedom.