Den 2021-07-05 kl. 16:07 skrev Tadziu Hoffmann:
> 
>>> echo ".ds head-str ${str: -1}"
> 
>> The compatible syntax is ${str:-1}.
> 
> I wonder if that is meant, though.
> 
> Bash also has
> 
>   ${parameter:offset}
>   ${parameter:offset:length}
>     Substring Expansion.  Expands to up to length characters of
>     the value of parameter starting at the character specified
>     by offset.

Aha, I see. That seems a bit dangerous...

In any case, the POSIX-compatible equivalent is

   echo .ds head-str `printf %s "$str" | tail -c1`

Unfortunately not as elegant as the reverse operation (${x%?}).


Reply via email to