Despite Judge Michael Slater's concerns about the dangers of carrying knives, he said he felt able to suspend the 12-month prison sentence he passed defendant, Eamon MacCarthy, for a period of two-years.
He said: "I've decided in your favour, that I am able to give you a chance."
Judge Slater added: "You've come very close to being sent to custody."
Sheffield Crown Court was told how MacCarthy carried out the offences on April 5 last year, when he visited Morrisons in Halfway.
"He picked up a box of Budweiser and some seafood and went out of the door without paying. He was stopped outside," said Louise Gallagher, prosecuting.
After being apprehended by the supermarket's security guards, MacCarthy, aged 35, was taken into an office to wait for the police, the court heard.
Ms Gallagher added: "He was seen to be fidgeting with something behind his back, and a member of the security staff saw him appear to drop something from his back pocket on to the floor.
"It appeared to be a knife."
The knife was between six and seven inches in length, and when interviewed by the police MacCarthy denied that the knife was his.
MacCarthy, of Golf Course Lane, Leicester later pleaded guilty to theft and possession of an article with a blade or point.
Defending, Chris Aspinall, told the court: "There's no suggestion he carries weapons with the intention of using them."
"The pre-sentence report puts forward that he would be suitable for unpaid work," added Mr Aspinall.
The court heard how MacCarthy has previously been convicted of over 30 criminal offences, including one of possessing a knife in 2003.
Under a 'two strikes' system introduced by the Government in 2015, minimum sentences were introduced for those aged 16 and over who are convicted of a second or subsequent offence of possession of a knife or offensive weapon.
Judge Slater imposed the minimum-term for two offences of carrying a knife, but said he felt able to suspend the custodial sentence in the circumstances.
In addition to his suspended sentence, Judge Slater also ordered MacCarthy to complete 120 hours of unpaid work as well as a 30-day rehabilitation activity requirement.