Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: ${var:1:1:=y}
- X-seq: zsh-users 19802
- From: Lawrence Velázquez <vq@xxxxxxxxx>
- To: Ray Andrews <rayandrews@xxxxxxxxxxx>
- Subject: Re: ${var:1:1:=y}
- Date: Tue, 3 Feb 2015 19:18:36 -0500
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=larryv.me; h= x-sasl-enc:content-type:mime-version:subject:from:in-reply-to :date:cc:content-transfer-encoding:message-id:references:to; s= mesmtp; bh=rEdVKSMbKNFUy5s7OLUcCamVKUE=; b=XK8mfMSKB+RaZyM72WgEJ lmGzLq0OFqZZj+dGSdu8DinQ8WiPbHBbeUAepltDalZ0dPG0aSZ3daisd0ds7GTk Pd4SHeiN4MtA5a6BzHbhcD87TH369BiG2QyRfJ2IiFuUPcD6DpuZ/pFOgqfh6p5g MY6KDOQSr/hTRGVEaI6h/U=
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=x-sasl-enc:content-type:mime-version :subject:from:in-reply-to:date:cc:content-transfer-encoding :message-id:references:to; s=smtpout; bh=rEdVKSMbKNFUy5s7OLUcCam VKUE=; b=ejeqEVXld5xabi3nMrQ0PHROsGl+WK3EY3X/8+pzHvzqBn+MbLRQlva ifRRWxbo5LzmUqghmkSy8hUvyddPb1mkPgvTBdolK6N9UidhswQsE8aRGz8lWl1c jDqPxLo0Uw6Gua6QETiAQ8ptbu+op8XwAGHCkJsACcop7Has8wk4=
- In-reply-to: <54D155C8.4080600@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: <54D155C8.4080600@eastlink.ca>
On Feb 3, 2015, at 6:12 PM, Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> We can of course do this:
>
> variable=${var:=xy}
>
> I'm wanting the naive expansion of that syntax to do this:
>
> variable=${var:1:1:=y}
>
> ... but it doesn't work. Can something like that be done?
(This is admittedly a non-answer, as I don't know whether there's a solution that's as succinct as you'd like.)
I would find that syntax (or something like it) very ambiguous. What would be assigned "y" in this case — `var`, or the slice of `var` that you were testing? Neither is obvious.
> At the moment I'm doing this:
>
> variable=${var:1:1}
> [ -n "$variable" ] || variable=y
>
> ... which is perfectly fine, but the above pseudosyntax would be elegant if it could be made workable.
Wouldn't testing the length of `variable` express your intent better?
> And I found something that puzzles me:
>
>
> test ()
> {
> echo $1
> echo ${1:0:1}
> /bin/echo ${1:0:1}
> echo ${1:1:1}
> echo ${1:0:1}${1:1:1}
> echo ${1:1:1}${1:0:1}
> }
>
> $ test -a
>
> -a
> [nothing]
> -
> a
> -a
> a-
>
> ... If I entered a valid switchofcourse I'd expect that to be eaten
> but a solitary dash? Bug? /bin/echo behaves as I'd expect.
Test cases should focus on the questionable behavior by discarding irrelevant details. Your case boils down to this:
% echo -
% /bin/echo -
-
%
vq
Messages sorted by:
Reverse Date,
Date,
Thread,
Author