From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.sysutils.supervision.general/2766 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Colin Booth Newsgroups: gmane.comp.sysutils.supervision.general Subject: Re: Does execline natively do arithmetic and branching Date: Thu, 19 Dec 2019 16:31:01 +0000 Message-ID: <20191219163101.GA12551@cathexis.xen.prgmr.com> References: <20191219080317.0b93894d@mydesk.domain.cxm> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="14466"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.10.1 (2018-07-13) To: supervision@list.skarnet.org Original-X-From: supervision-return-2355-gcsg-supervision=m.gmane.org@list.skarnet.org Thu Dec 19 17:31:06 2019 Return-path: Envelope-to: gcsg-supervision@m.gmane.org Original-Received: from alyss.skarnet.org ([95.142.172.232]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1ihyhe-0003ai-32 for gcsg-supervision@m.gmane.org; Thu, 19 Dec 2019 17:31:06 +0100 Original-Received: (qmail 15346 invoked by uid 89); 19 Dec 2019 16:31:29 -0000 Mailing-List: contact supervision-help@list.skarnet.org; run by ezmlm Original-Sender: Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Original-Received: (qmail 15339 invoked from network); 19 Dec 2019 16:31:29 -0000 Content-Disposition: inline In-Reply-To: <20191219080317.0b93894d@mydesk.domain.cxm> Xref: news.gmane.org gmane.comp.sysutils.supervision.general:2766 Archived-At: On Thu, Dec 19, 2019 at 08:03:17AM -0500, Steve Litt wrote: > Hi all, > > I'm messing around with execline, in the hopes that in long tight loops > it can be faster than /bin/sh. Now I want to do incrementing and other > add/subtract. Is there any kind of native way, or do I need to backtick > dc? It depends on what you're trying to do. If you're trying to generate an iterative set to work on (for i in `seq 1 10 ; do ...`) you can do it with `forbacktickx VAR { seq 1 10 } ... '. However, as mentioned in the loopwhilex documentation: Be careful: execline maintains no state, in particular it uses no real variables, and environment will be of no use here since every instance of prog... runs as a separate child process. Which makes doing true incrementers not possible without using the file syustem (for example, you can't run a program in a loop and feed the results back into the next execution of that loop without offloading your computation results to disk). If instead you're trying to do actual math (`$((N+1))' and the like), no execline does not support that. At least, not as far as I know. This is because once a script has gone through the initial parsing and environmental manipulation it stops being an execlineb script and instead becomes a whatever-the-next-program-in-the-chain-is script. Unlike shell there is no overarching program managing everything so you can't differ higher level processing and data storage once the program has started. > > Second question: Is there a way to find out whether a variable is ten > or above without using execline's ifthenelse to query the test > executable? > Just like in shell you need to call test (either the builtin or stand-alone variety). Depending on how you want the program to proceed if, ifelse, ifte, or ifthenelse are all perfectly valid callers, but `if [ 10 -lt $VAR ] ; then do thing ; else do other ; fi ...' is written `importas VAR VAR ifthenelse { test 10 -lt ${VAR} } { do thing } { do other } ...' (the importas is, of course, not necessary if you've imported/defined/whatevered it earlier). Anyway, the only difference is that execline doesn't have a built-in mechanism for truth testing but having that somewhere on a system is a requirement for POSIX so execline itself doesn't need to ship one. Of course, execline itself doesn't have any builtins per-se (the commands shipped with execline are stand-alone utilities) so you can't fudge it like you can with shell. If you don't want to use the GNU or BSD coreutils, and are allergic to multi-call binaries, s6-test (in s6-portable-utils) works quiet well and handles all of the POSIX defined cases. -- Colin Booth