Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Negative length parameter expansion



12.04.2015, 10:47, "Thorsten Kampe" <thorsten@xxxxxxxxxxxxxxxx>:
> Hi,
>
> Bash got negative length parameter expansion (like in `${STRING:11:-
> 17}`) in version 4.2 and Zsh in 4.3.12.
>
> How would I do negative length parameter expansion in Bash or Zsh if
> my version doesn't support it?
>
> Thorsten

`$#STRING` is a length of the string. `-17` is `$(( ${#STRING}-17+1 ))`. (`$(( ))` may be not necessary, most likely they will not be necessary in zsh, don’t know about bash). `${#PARAMETER}` form is supported by any POSIX shell (but not `$#PARAMETER` without figure braces).



Messages sorted by: Reverse Date, Date, Thread, Author