From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23697 invoked by alias); 4 Feb 2015 03:25:41 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 19805 Received: (qmail 28158 invoked from network); 4 Feb 2015 03:25:39 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=PYxIXZlY c=1 sm=1 tr=0 a=FT8er97JFeGWzr5TCOCO5w==:117 a=kj9zAlcOel0A:10 a=q2GGsy2AAAAA:8 a=oR5dmqMzAAAA:8 a=-9mUelKeXuEA:10 a=0HtSIViG9nkA:10 a=BICfR2TBv_BCqPSFhJwA:9 a=CjuIK1q_8ugA:10 From: Bart Schaefer Message-id: <150203192508.ZM2159@torch.brasslantern.com> Date: Tue, 03 Feb 2015 19:25:07 -0800 In-reply-to: <54D155C8.4080600@eastlink.ca> Comments: In reply to Ray Andrews "${var:1:1:=y}" (Feb 3, 3:12pm) References: <54D155C8.4080600@eastlink.ca> <412544FB-49A2-43AA-BC76-DC1AF1AA71BE@larryv.me> <54D16A4C.9010609@eastlink.ca> In-reply-to: <412544FB-49A2-43AA-BC76-DC1AF1AA71BE@larryv.me> Comments: In reply to Lawrence Velazquez "Re: ${var:1:1:=y}" (Feb 3, 7:18pm) In-reply-to: <54D16A4C.9010609@eastlink.ca> Comments: In reply to Ray Andrews "Re: ${var:1:1:=y}" (Feb 3, 4:39pm) In-reply-to: Comments: In reply to Lawrence Velazquez "Re: ${var:1:1:=y}" (Feb 3, 8:30pm) X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh Users Subject: Re: ${var:1:1:=y} MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Feb 3, 3:12pm, Ray Andrews wrote: } } 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? Jumping several messages ahead: } assign to 'variable' either the value of the second character of 'var' } (just one character), and if that does not exist, assign 'y' You've forgotten that ${var=val} has the side-effect of assigning to "var" if it is not set. I think what you mean is what Lawrence already demonstrated (again several messages ahead): variable=${${var:1:1}:-y} However, you can do this with subscript syntax: variable=${var[2]:=y} which either assigns to $variable the second character of $var, or assigns "y" to both $variable and to the second character of $var. E.g.: torch% var=a torch% variable=${var[2]:=y} torch% typeset -m var\* variable=y var=ay torch% You can also do ${var[2]::=z} to forcibly assign "z" to the second character of $var. On Feb 3, 7:18pm, Lawrence Velazquez wrote: } Subject: Re: ${var:1:1:=y} } } Test cases should focus on the questionable behavior by discarding } irrelevant details. Your case boils down to this: } } % echo - } } % /bin/echo - } - } % Yes, the manual says (in the introduction to section 17 Shell Builtin Commands and at the top of "man zshbuiltins"): All builtin commands other than precommand modifiers, even those that have no options, can be given the argument `--' to terminate option processing. This indicates that the following words are non-option arguments, but is otherwise ignored. This is useful in cases where arguments to the command may begin with `-'. For historical reasons, most builtin commands also recognize a single `-' in a separate word for this purpose; note that this is less standard and use of `--' is recommended. (Actually the doc might not say exactly that due to a Yodl formatting error, but that's what it is supposed to say. The part about a single `-' in a separate word is correct and is what matters here.)