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 22303 invoked from network); 1 Dec 2020 07:37:28 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 1 Dec 2020 07:37:28 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1606808249; b=DiuKKoN3wsdhptXBgHzqGYPJXifUZj6XWPmUHI5uhUJo1kX6Ue6Q+tsk+V6DPijznhBYELvOtC fLD/NHCkEU1BYIPT3tqv2IhNix3OfbHBSxXIoHwr4jWMvh/qu/SDa87JIQMVBE3DJBCgYwMXDt B+p2RrF7VP7Omc1VgI9NdD0reZYka+rMPtgWQXDurNuzHRjcSOWrz/aO73w7aG522pmacxAPjE x48Y2wFb8uV/DY6K+JAjDLZXsMsP5svagZ9BaLWlN+6SFTuz5NQg/T93cGNVmOyXHZKd3CUxOl LzpyfV9bewVy5PIeZvuOU7UVc3MStqkaOa0jCr3AakyiqQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail.velocitynet.com.au) smtp.remote-ip=203.55.137.25; dmarc=none header.from=goldweb.com.au; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1606808249; bh=A5OiFD6yXirSi/xhbyburbc/DbSa8kufRqd1r1SQlxw=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Message-ID:In-Reply-To:To:References:Date:Subject: MIME-Version:Content-Transfer-Encoding:Content-Type:From:DKIM-Signature; b=pm2LClkOZAS0WXO1lyEZ+sZunZZt8xvWjm3f0xYn3bpBJLGRmutZuj7vD2Ip1yWqxXTuO1DiZm nSK9dBiEoreDa16wk2IiS2Odbftvuj97JIFnfECApzlB2yy82pQrf4DM0Lyrwf8GdNuL04pbU/ KZdfTgUZF0vbakxGijs6fHx1s5PxicrIzLI7WZj3bTtsVCxgmOMEFR19CORpwhxP2M1G+6Lixv nzkPF4plKC77OwMQc1aSSVPlR8KtWNIozlnjBD5iMooPDA06ahJsIKNwZ0T+rVNFFs59iVdBJZ Uua/O6lRQE3eMOHvozil+/3IWnEx4GBY+E0Q5CUWcJoChg==; 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:Message-Id:In-Reply-To:To:References: Date:Subject:Mime-Version:Content-Transfer-Encoding:Content-Type:From: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=qBoMg/VSRK+M3DIzlNkCjen0yjfBIqkEipbRneMluC8=; b=M9l/zWG1MR+XVMFmAXJRvBt9NB /6qN1uTQnBNP/Yp6/Cy3WRjuJLHw01ui6+Wqf5iWuStRcpR6iwSYgF2rDMBjwBgjktROFYF3tqW22 nISSkJc/R+o3tsesmzkhL81ufxwt04irXXCWpz9SoRy8VmFIeci3qMz6sa8LRYl/jaaBQaHPOkllm klkzk9EhjoM3yzdaAK0gJxmRWYutvTXpYPChAJ5UbkWIJ2Yb2OcY/bwdaob6Qw7upMOTFX3Y4bU9c AQWFrwqX2dXEKzuEfS7+YYbELzyB2kXJxZZS/e4g7n9kZbcEeKfJvPNnCruNVce70EbfqxIrve064 wjZffYVQ==; Received: from authenticated user by zero.zsh.org with local id 1kk0Dw-000I3e-RK; Tue, 01 Dec 2020 07:37:20 +0000 Authentication-Results: zsh.org; iprev=pass (mail.velocitynet.com.au) smtp.remote-ip=203.55.137.25; dmarc=none header.from=goldweb.com.au; arc=none Received: from mail.velocitynet.com.au ([203.55.137.25]:44604) by zero.zsh.org with esmtp id 1kk0DR-000Gpa-18; Tue, 01 Dec 2020 07:36:53 +0000 Received: from manicdee.com (58-6-171-32.dyn.iinet.net.au [58.6.171.32]) by mail.velocitynet.com.au (Postfix) with ESMTPSA id D6B3B60002 for ; Tue, 1 Dec 2020 18:36:38 +1100 (EST) Received: from [127.0.0.1] (localhost [127.0.0.1]) by manicdee.com (Postfix) with ESMTP id C08CF30227490C for ; Tue, 1 Dec 2020 18:36:36 +1100 (AEDT) From: Alex Satrapa Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.17\)) Subject: Re: infinite loop that is possible to quit Date: Tue, 1 Dec 2020 18:36:36 +1100 References: <875z5m9twt.fsf@zoho.eu> To: zsh-users@zsh.org In-Reply-To: <875z5m9twt.fsf@zoho.eu> Message-Id: X-Mailer: Apple Mail (2.3445.104.17) X-Seq: 26204 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: There's no real "good" or "bad" decision here until you start doing = stuff inside that loop. How will immediately halting processing of that = script cause trouble later? Will you corrupt data? Leave a peripheral in = an unknown state? If there's no concern about data corruption, allowing = Ctrl+C (or SIGTERM) terminate the processing of the script is fine. Other options include: 1. Reading user input and looking for eg "q" being pressed 2. Looking for a specific file on the file system, eg ".stop" and = stopping when that file appears 3. Looking for a specific file on the file system, eg "config" and = stopping when that file disappears 4. Using a settings file which you watch for changes, reread the = settings, and get the stop/go from a config settings 5. Catching Ctrl+C (SIGTERM) and handling it (more about that later) #!/bin/zsh =20 CONTINUE=3D1 =20 wrap_up() { echo "Wrapping up." CONTINUE=3D0 } =20 trap 'wrap_up' HUP INT QUIT TERM =20 while [ $CONTINUE -eq 1 ] ; do echo "I'm still here." sleep 5 done Which will produce something like: [user@host]$ ./traptest I'm still here. I'm still here. ^CWrapping up. The traps I'm catching there are the ones usually associated with a soft = shutdown. HTH HAND > On 1 Dec 2020, at 12:50, Emanuel Berg wrote: >=20 > How do I do an infinite loop that runs something, but it will > still be possible to quit the whole thing? >=20 > The best thing I've come up with is >=20 > while true; do > # run program > sleep 1 > done >=20 > Then do, say, q to exit the program, and C-c during the sleep > period to quit the loop! >=20 > Is this good or bad? >=20 > TIA >=20 > --=20 > underground experts united > http://user.it.uu.se/~embe8573 > https://dataswamp.org/~incal >=20 >=20