Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: ${var: -1:1} vs. ${var:-1:1}
- X-seq: zsh-users 17404
- From: Moritz Bunkus <moritz@xxxxxxxxxx>
- To: Ray Andrews <rayandrews@xxxxxxxxxxx>
- Subject: Re: ${var: -1:1} vs. ${var:-1:1}
- Date: Sat, 17 Nov 2012 22:48:56 +0100
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/simple; d=bunkus.org; s=mail201203; t=1353188939; bh=+r09fDbwoMef+1rrvgOfpdql8KgftMfxJv/fKkT5xCY=; h=MIME-Version:In-Reply-To:References:Date:Message-ID:Subject:From: To:Cc:Content-Type; b=AdjJZm9SE9+xoqmpp8EUhaWd0PmaKFrNZ2JXCXaisL8vpChaeMCA+KqqN8iMvmaeK lCB/SWQaK+2+JX6D2uAo4btr4X9N8Ffx7Ra+s0zAcm6S+N6jPtwG8vfvcapY6uEtpT AsWrLIy5PbbW3DRQHHDiDssNT6Vkekr61dXSRsB4=
- In-reply-to: <50A7FD3C.9070306@eastlink.ca>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <50A7FD3C.9070306@eastlink.ca>
Hey,
if you don't put a space there then the parser thinks that this the
"${variable:-default} syntax which means "expands to the variable's
content if the variable is set and to 'default' if it is unset". Can
be seen easily with:
[0 mosu@sweet-chili ~] echo ${thisvarisnotset:-1:1}
1:1
So the '1:1' is interpreted as the 'default'. You probably never saw
that result because you were trying to extract the last character from
a string, meaning you always used a variable that was set.
Kind regards,
mosu
Messages sorted by:
Reverse Date,
Date,
Thread,
Author