Robert Ramsay pleaded guilty to possession of an offensive weapon at the town’s Tesco store on the night of August 20.
Jedburgh Sheriff Court heard that staff at the Paton Street supermarket called police after being informed that there was a man with a knife in its car park.
When officers caught up with Ramsay outside a pizza shop in Channel Street, they could see the weapon, with a five-inch blade and black handle, sticking out of the waistband of his trousers.
Judging him to be under the influence of an unknown substance, they immediately subdued him by wrestling him to the ground.
When cautioned and charged, Ramsay, giving an address in Maxmill Park in Kelso, claimed that knife was for his protection as he and his brother, he said, had been run out of Hawick by men brandishing swords.
He also admitted attempting to break into the 1905 bar in Kelso on October 16 and breaching a night-time curfew after being spotted in the grounds of the town’s Ednam House Hotel on January 18.