Date: Wed, 8 Nov 2017 14:42:28 +0100 From: Polytropon <freebsd@edvax.de> To: Arthur Chance <freebsd@qeng-ho.org> Cc: freeBSD Mailing List <freebsd-questions@freebsd.org> Subject: Re: how to code a timer loop in a sh script Message-ID: <20171108144228.eeb81eaa.freebsd@edvax.de> In-Reply-To: <95cc2469-955e-02c1-3cdd-82e630feaa1c@qeng-ho.org> References: <5A00A826.2000501@gmail.com> <CADqw_g%2BouzDLBdPosKiPSmRZuP6Am%2Bc7OGUZPGWX249D97DUhQ@mail.gmail.com> <alpine.BSF.2.21.1711080824130.1036@mail.fig.ol.no> <20171108135659.dab81adf.freebsd@edvax.de> <95cc2469-955e-02c1-3cdd-82e630feaa1c@qeng-ho.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 8 Nov 2017 13:23:14 +0000, Arthur Chance wrote: > On 08/11/2017 12:56, Polytropon wrote: > > On Wed, 8 Nov 2017 08:25:55 +0100 (CET), Trond Endrest=F8l 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 > >=20 > > Yes. > >=20 > > 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. > >=20 > > From "man test": > >=20 > > string True if string is not the null string. > >=20 > > As the 1 is the only expression tested, this rule applies. > > No math included. ;-) >=20 > 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. :-) That's correct (at least in FreeBSD's /bin/sh; other implementations might not have those as builtins - in case script portability should be important here). I still agree with you that true or : aren't as "heavy on resources" as test (either as builtin or external program call); as if anyone cares for efficiency today... ;-) --=20 Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20171108144228.eeb81eaa.freebsd>