From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 8968 invoked from network); 1 Dec 2020 09:53:49 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 1 Dec 2020 09:53:49 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1606816429; b=nbNuMl/ctcBQ2lDxE3nKIWhUg/RlGJrRmHrWDG0o3DEnpsSUIGh7mmDMChP8abgsmvpPpCR2E9 xG63WewmST79CNWHr3bXsBKKYpvDBu+mPgKtf1g0SnTQBxKtvZ69HmH0VIYU58utHPekMKG0GP yrsggt0l7/lIvdmvjjs2PbWbP0rX6x1Jkvh9tzxZ7Z4SyG+aYNPcvaN8PhCAk6Dq1IPjyaodaN xrfQ/DQXjqlbyN/0jMTo8wblXKNrHoEug9DJr22RPAUL88dnKRrt0/h5BDMO5uG8qc5ZS30G00 RYniFnMxg7uj/LyOh1R4dxqPiUEK5GFmYpPLloBsR/3IIg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail.covisp.net) smtp.remote-ip=65.121.55.42; dmarc=none header.from=covisp.net; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1606816429; bh=2Y1ahpFTBjxkx77ex12DoFh1HoV/bHskdgPRxPc0wag=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:To:References:Message-ID:Content-Transfer-Encoding:Date: In-Reply-To:From:Subject:Content-Type:DKIM-Signature; b=ltEgASDtImBW10uQtppKuahYtpJjh5fe3naKGZXYu/H8wJ6NLYQVebO4JjPJWj5o4L931MnstH g/Qo4OKgMOZOH+x3Q4fNiF68CMRVbubYkFd2yqYJS08rwEwyqNP1Gw2pkkeq0UXy6hka8UbzQS mIkBg7m21i0BlQw5bAMwlZ1H6a7cT4YuY/G9xWtk0tlZvB14ly82OHnrAkeFwtpLT37WFz7161 8pnWwrqbYayjyVjRiZXrq86Ugondi7WD5rtTjSF9sz6VQkLpxwN/r2jeDILjO/fFyhJ3ex07DD 5Zs6JUVGqV9jWCuqr70dfpyxvgwGG30xrjPaShM0KVhJlw==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:To:References:Message-Id: Content-Transfer-Encoding:Date:In-Reply-To:From:Subject:Content-Type:Reply-To :Cc:MIME-Version:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=KME21SsM9ikagZ2JR4+WXFAMnOPFgONamKTKZoG02rA=; b=Jo2g0cE27sqq2J0RtoTIPZ5Kag dqbi3QktWUSuq0siQupIVf5kcBnKua1SL+QZPDMQVEa9CpFBWIl0gPlmejL0ySuAyZO8AFkB8SeFH kMfHeqfSVDjxxfQNn4SLvheVR8RdpeKXcwmJL+SoSTHbKeoeaiF7LRMENrwjGj39YR5a+OylzUL2S DfEsyVRQyVEO2PXo/1AjX1+qDc7m+eA4DOtQbi9QlgDaKs/nzXtXjyVmdlne9FE29OjrazwGlIs4o FvTIsU3E61587BR/7Hi1HbyHDvSCgnuedy7fU1MK3SlQY13neIsJcN+xtgL/mJHOXz0xaP0YSOutk XLkOKMgw==; Received: from authenticated user by zero.zsh.org with local id 1kk2Ly-000Chx-3M; Tue, 01 Dec 2020 09:53:46 +0000 Authentication-Results: zsh.org; iprev=pass (mail.covisp.net) smtp.remote-ip=65.121.55.42; dmarc=none header.from=covisp.net; arc=none Received: from mail.covisp.net ([65.121.55.42]:37800) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1kk2LH-000BDj-9K; Tue, 01 Dec 2020 09:53:04 +0000 Content-Type: text/plain; charset=utf-8 Subject: Re: infinite loop that is possible to quit From: Lewis Butler In-Reply-To: <875z5m9twt.fsf@zoho.eu> Date: Tue, 1 Dec 2020 02:53:00 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: <360E0D44-A1C0-4D68-A2B4-4B017F2EB277@covisp.net> References: <875z5m9twt.fsf@zoho.eu> To: Zsh Users X-Mailer: Apple Mail (2.3654.40.0.2.21) X-Seq: 26205 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: On 30 Nov 2020, at 18:50, Emanuel Berg wrote: > while true; do > # run program > sleep 1 > done Since I tend to use loops like this just to do simple things like check = status on some other process, that is the method I mostly use (though = usually with a sleep 5 or 30 or 300, very rarely a sleep 1). When you = get to more complicated scripts though, it is better to have some brains = in the script for terminating cleanly. How you do that depends very much on what you are doing. I like grail@goldweb.com.au's example of trapping TERM QUIT and HUP, but = that is not always the best solution either. For example, I used to have a pair of scripts. One checked that a = network mount was enabled and if it vanished, it remounted it, and = restarted the second script. The other synced files to the network = mount. When the second script was done, it wrote a file to the network = with the output of the sync (how many files, how much data was = transferred). When the first script saw that file, it exited. This was necessary when I had a somewhat unreliable network connection = to the remote server. Or at least it was the simplest way I had at the = time to ensure that the network sync happened as quickly as possible and = that I didn't end up with an incomplete sync because the network had = gone offline for 40 seconds at 03:19. Basically, when you have an infinite loop, you have to have an idea of = what is going to end that loop, and what makes sense depends on what the = loop is doing. It may be a file, or a time, or user intervention, or a = particular condition on the machine. All are valid, and which is best = depends on what you're trying to achieve. --=20 =C9=B9=D7=9F=CA=87nq=D7=9F tel:+1.303.219.0564