Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

10
  • Nice and thorough! But... I assume all of those shells support POSIX, so everyone should just use that one to be the most portable. Smallest character count, too! Commented Sep 16, 2016 at 3:20
  • @Russ, t=${t%?} is not Bourne but you're not likely to come across a Bourne shell nowadays. ${t%?} does work in all the other ones though. Commented Sep 16, 2016 at 6:53
  • No fish shell option given! Probably more popular these days than ksh93... Commented Nov 18, 2017 at 1:21
  • @rien333. I'd wait for the interface to stabilize a bit. fish is work in progress. 2.3.0 which introduced the string builtin was not released at the time of the Q&A. With the version I'm testing it on, you need string replace -r '(?s).\z' '' -- $t (and I'd expect they'd want to change that, they should change the flags they pass to PCRE) or more convoluted ones. It also deals poorly with newline characters, and I know they're planning on changing that as well. Commented Nov 18, 2017 at 8:10
  • 1
    @Timo, not sure what you mean. None of the solutions I gave are bash-specific. The only one invented by bash AFAIK is t=${t:0:-1} (extending the ${var:offset:length} ksh93 operator). For each, I gave which shells support it. You can use the Bourne/POSIX ones from and modern sh. Commented Nov 16, 2020 at 14:02