How Can I Remove Last Character from a String in Unix?
Contents

How do I remove the last character of a string in Shell?

Bash/ksh shell substitution example

The syntax to remove last character from line or word is as follows: x=”foo bar” echo “${x%?}”

How do I remove the last character in Linux?

s/. $// replaces the last character on the (in this case last) line with an empty string; i.e., effectively removes the last char.

Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest