From owner-freebsd-questions@freebsd.org Wed Nov 8 13:49:21 2017 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8A76FE540B3 for ; Wed, 8 Nov 2017 13:49:21 +0000 (UTC) (envelope-from freebsd@qeng-ho.org) Received: from bede.home.qeng-ho.org (bede.qeng-ho.org [217.155.128.241]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "fileserver.home.qeng-ho.org", Issuer "fileserver.home.qeng-ho.org" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 292587B702 for ; Wed, 8 Nov 2017 13:49:20 +0000 (UTC) (envelope-from freebsd@qeng-ho.org) Received: from arthur.home.qeng-ho.org (arthur.home.qeng-ho.org [172.23.1.2]) by bede.home.qeng-ho.org (8.15.2/8.15.2) with ESMTP id vA8DNEVe019449; Wed, 8 Nov 2017 13:23:15 GMT (envelope-from freebsd@qeng-ho.org) Subject: Re: how to code a timer loop in a sh script To: Polytropon Cc: freeBSD Mailing List References: <5A00A826.2000501@gmail.com> <20171108135659.dab81adf.freebsd@edvax.de> From: Arthur Chance Message-ID: <95cc2469-955e-02c1-3cdd-82e630feaa1c@qeng-ho.org> Date: Wed, 8 Nov 2017 13:23:14 +0000 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171108135659.dab81adf.freebsd@edvax.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 8bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Nov 2017 13:49:21 -0000 On 08/11/2017 12:56, Polytropon wrote: > On Wed, 8 Nov 2017 08:25:55 +0100 (CET), Trond Endrestøl wrote: >> On Mon, 6 Nov 2017 19:24+0100, Michael Schuster wrote: >> >>> while [ 1 ]; do >>> do_stuff >>> sleep 600 >>> done >> >> This should be even better: >> >> while true; do >> do_stuff >> sleep 600 >> done > > Yes. > > While /usr/bin/true always evaluates to true (as desired), > "test 1" depends on if it's an internal or external command > which depends on the shell, and if the implementation conforms > to the standard. In this specific case, 1 would be seen as "1", > a non-empty string, and therefore should cause test to return 0, > as a non-empty string evaluates to true. > > From "man test": > > string True if string is not the null string. > > As the 1 is the only expression tested, this rule applies. > No math included. ;-) A minor point: in /bin/sh "true" and "test" are builtins (with synonyms ":" and "[" respectively). true (and :) don't need to test anything, so shave microseconds off the 10 minute sleep cycle. :-) -- An amusing coincidence: log2(58) = 5.858 (to 0.0003% accuracy).