how to code a timer loop in a sh script
Arthur Chance
freebsd at qeng-ho.org
Wed Nov 8 13:49:21 UTC 2017
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).
More information about the freebsd-questions
mailing list