From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 225 invoked by alias); 12 Feb 2017 06:19:09 -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: 22454 Received: (qmail 15814 invoked from network); 12 Feb 2017 06:19:09 -0000 X-Qmail-Scanner-Diagnostics: from out4-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(66.111.4.28):SA:0(-0.7/5.0):. Processed in 1.056094 secs); 12 Feb 2017 06:19:09 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= mesmtp; bh=gQ/xltkg1Zfhi7GotHfJd8pddxk=; b=XmXc+sLZXis5uCHwazSjb oaHlhtslppZ7iAOqIKgWIgAEEvTiwVkA2uWEDKee5hEGE4W3HQ9hY7ahAjmCfNVN pIa4HpPVF/mUb+MmJRUFSzmKy16AzQgcyCRnQcnVEybphm44kt9PHaDGCasurub1 aOwbRIeD9VVDyQK+Oxte7w= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= smtpout; bh=gQ/xltkg1Zfhi7GotHfJd8pddxk=; b=V8G7TVQNJRChFaqEGFeF NIUIZdF0CBSMKa94rJ/G6v+JzWs4/Z4iC85ji5OgiHUprmwpLofthom0hm5YtHLh BF1K6WVKdblC++rQ+LoIy95V17qlNPrlPRbL0MWtMOuKQrRUobrai63erYC81jDG 5Hczi19SR4dQRzrdTFvGGvI= X-ME-Sender: X-Sasl-enc: zl5rCXtj7VlxeiO0ABkpCkqoX886DlnqnVd1o3yXr8Ci 1486880342 Date: Sun, 12 Feb 2017 06:14:55 +0000 From: Daniel Shahaf To: Ray Andrews Cc: zsh-users@zsh.org Subject: Re: padding. Message-ID: <20170212061455.GA4267@fujitsu.shahaf.local2> References: <0befdb38-eaa5-6388-a3fe-58b1a73834b7@eastlink.ca> <170211110437.ZM467@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) [@all: the second hunk is of independent interest] Ray Andrews wrote on Sat, Feb 11, 2017 at 17:54:09 -0800: > On 11/02/17 11:04 AM, Bart Schaefer wrote: > >integer -Z 6 vvar=-1 > > Perfect! Amazing what's hiding under the hood. I always prefer to do as > much as possible with built in functionality. > >I don't think you can, except by specifying a field width of 6. Even > >printf is going to treat the "-" as part of the field width. > > Yeah, it would be more complicated and more involved to get a neat printout. > The engineer in me does want the field width to be independent of the sign, > but it's a trivial matter. printf is not a reserved word (it isn't part of the syntax), however, it _is_ builtin to the shell: % which printf printf: shell built-in command If printf weren't a builtin, it wouldn't have been able to grow the «-v variablename» flag. > BTW, is this kosher: > > > $ if [ "$1" = "start" ]; then > if [ "$1" = 'null' ] && return > fi > > (no message) Reduced example: % if false; then if true; fi % setopt noshortloops % if false; then if true; fi zsh: parse error near `fi' I'm guessing the second 'if' is parsed using the SHORT_LOOPS syntax, with an empty sublist. I'm not sure whether that's a bug: is the sublist in the SHORT_LOOPS syntax allowed to be null? What about the following variant: if true; then if exit 42; fi Should it exit() or report a syntax error about a missing 'fi'? > and: > > $ if [ "$1" = "start" ]; then > # if [ "$1" = 'null' ] && return > fi > > (no message) That's expected. In a script or with INTERACTIVE_COMMENTS, the outer if's body is empty. Interactively and with INTERACTIVE_COMMENTS unset, the outer if's body invokes the '#' command with its ${argv[1]} set to the two-character string "if". That would report "command not found" if the outer condition were true, but is nonetheless not a syntax error; it's exactly equivalent to: if false; then this-is-not-a-command-name arg1 arg2 fi which is not a syntax error, either. It's a runtime error. > but: > > $ # if [ "$1" = "start" ]; then > if [ "$1" = 'null' ] && return > # fi > > ./test2:7: parse error near `\n' Again, this is parsed differently depending on whether comments are being parsed. With comments enabled, this is a syntax error because the if on line 2 is unterminated. With comments disabled, this is a syntax error because the 'then' on the first line doesn't follow an if. Cheers, Daniel