How to trim leading and trailing characters in Bash? Aug 25, 2020 Bash has built-in facilities to trim characters at the beginning and end of the value of a variable: $ myvar="AAAthis is a testAAA" $ echo ${myvar##*(A)} this is a testAAA $ echo ${myvar%%*(A)} AAAthis is a test