From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29119 invoked by alias); 19 Oct 2017 08:59:40 -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: List-Unsubscribe: X-Seq: 22945 Received: (qmail 28328 invoked by uid 1010); 19 Oct 2017 08:59:40 -0000 X-Qmail-Scanner-Diagnostics: from aurora-borealis.phear.org 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(94.242.205.164):SA:0(-0.4/5.0):. Processed in 3.858733 secs); 19 Oct 2017 08:59:40 -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.4 required=5.0 tests=BAYES_00,FAKE_REPLY_C, RP_MATCHES_RCVD,T_SPF_TEMPERROR autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: khatar@phear.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | X-Virus-Scanned: amavisd-new at phear.org Date: Thu, 19 Oct 2017 08:49:38 +0000 From: Marc Chantreux To: zsh-users@zsh.org Subject: Re: s2hms Message-ID: <20171019084938.GA11689@aurora-borealis.phear.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <86h8uw14ho.fsf@zoho.com> User-Agent: Mutt/1.7.2 (2016-11-26) hello, you don't need the $data buffer as you can read directly in varibles. my (untested) version should be more like s2hms () { # clean error message when no argument passed local secs=${1?duration in seconds} it= out= local -a fields=( h m s ) local -A duration # duration\[$^fields] is a short for # duration\[h] duration\[m] duration\[s] units -t $secs\s hms | IFS=\; read duration\[$^fields] # use mathematical context to do math # also: a value is 0 or >0 so just test if it's >0 for it ($fields) (( duration[it] )) && out+="$duration[$it]$it" print $out } HTH regards -- Marc Chantreux (eiro on github and freenode) http://eiro.github.com/ http://eiro.github.com/atom.xml "Don't believe everything you read on the Internet" -- Abraham Lincoln