Examples:
Code: Select all
# This works ( notice compound "Len=" statenment ):
Str=123A456 ; First=${Str:0:1} ; Len=$((${#Str}-1)) ; Last=${Str:$Len:1}
echo -e '\n### First letter: '$First' \n### Last letter: '$Last
# And this:
S='1 2 3'
S="${S//[^ ]/}"; echo ${#S}
# But this errors:
S='1 2 3'
echo ${#${S//[^ ]/}}
But a string length can`t have a replacement in it.