bash – getting part of variable (e.g. last 4 characters and prefix)

Recently, I had this small issue: how to split variable in bash without too much effort?

I wanted to split it into two parts: prefix and suffix.

There were few assumptions, when it comes to variable value.

– length of variable is >= 5
– it has fixed length of suffix (4 characters)
– prefixes length can vary

suffix=${variable: -4}
echo "variable: $variable prefix: $prefix suffix $suffix"