A man came to the Prophet ﷺ and asked, "One man fights for spoils, another fights for fame, and another fights to be seen. Which of them fights in the path of Allah?"He replied, "Whoever fights so that the word of Allah may be supreme is the one who fights in the path of Allah."
جاء رجل إلى النبي ﷺ، فقال: الرجل يقاتل للمغنم، والرجل يقاتل للذكر، والرجل يقاتل ليرى مكانه، فمن في سبيل الله؟ قال: من قاتل لتكون كلمة الله هي العليا، فهو في سبيل الله.
Bukhari reported it in the Book of Jihad and Expeditions (2810), and Muslim in the Book of Leadership (1904), both through Shuba, from Amr bin Mura, who said, I heard Abu Waail say, Abu Musa Ashari narrated to us, and he mentioned it. The wording given here is Bukhari's.