[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Duration between two time stamps
From: |
Tapani Tarvainen |
Subject: |
Re: Duration between two time stamps |
Date: |
Fri, 20 Aug 2021 09:31:48 +0300 |
On Thu, Aug 19, 2021 at 10:47:35AM -0400, Chet Ramey (chet.ramey@case.edu)
wrote:
> On 8/19/21 1:10 AM, Tapani Tarvainen wrote:
>
> > Incidentally, why does ${var:offset} with a negative offset result in
> > an empty string when the variable is shorter than the offset? E.g.,
> >
> > x=abc
> > echo ${x: -6}
> >
> >
> > I find that counterintuitive,
>
> Why? It's an out-of-bounds error.
Maybe my intuition is strange, but when I specify "last six characters"
of a string that's shorter, I find it odd to get an empty string.
I would understand if it actually generated an error (like ${x::-6} does),
but returning an empty string silently is surprising.
In general, when I try to do something that can't be done, the expected
result is either an error message or leaving the input unchanged.
In this particular case it is debatable which would be better, but
I think the latter is likely to useful more often.
> > and it'd actually be useful to
> > be able to get "at most N characters from the end".
>
> If you want that, you can use ${#x} to get the length and work from there.
Sure. And there are other ways, too. None quite as easy though.
--
Tapani Tarvainen
- Re: Duration between two time stamps, (continued)
- Re: Duration between two time stamps, Alex fxmbsw7 Ratchev, 2021/08/19
- Re: Duration between two time stamps, Greg Wooledge, 2021/08/19
- Duration between two time stamps, hancooper, 2021/08/19
- Re: Duration between two time stamps, Koichi Murase, 2021/08/19
- Re: Duration between two time stamps, Koichi Murase, 2021/08/19
- Re: Duration between two time stamps, Tapani Tarvainen, 2021/08/20
- Re: Duration between two time stamps, Chet Ramey, 2021/08/19
- Duration between two time stamps, hancooper, 2021/08/19
- Re: Duration between two time stamps, ikhxcsz7y xmbott, 2021/08/19
- Re: Duration between two time stamps, Emanuele Torre, 2021/08/19
- Re: Duration between two time stamps,
Tapani Tarvainen <=
Re: Duration between two time stamps, Chris Elvidge, 2021/08/19
Re: Duration between two time stamps, Alex fxmbsw7 Ratchev, 2021/08/19
Re: Duration between two time stamps, Lee, 2021/08/19