I have a variable var in a Bash script holding a string, like:
echo $var
\"some string.rtf\"
I want to remove the last 4 chara
Using Variable expansion/Substring replacement:
${var/%Pattern/Replacement}
If suffix of var matches Pattern, then substitute Replacement for Pattern.
So you can do:
~$ echo ${var/%????/}
some string
Alternatively,
If you have always the same 4 letters
~$ echo ${var/.rtf/}
some string
If it's always ending in .xyz:
~$ echo ${var%.*}
some string
You can also use the length of the string:
~$ len=${#var}
~$ echo ${var::len-4}
some string
or simply echo ${var::-4}