A 21-year-old man who was waiting for a train into Glasgow has been jailed after £38,000 was discovered in his rucksack.