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=-1.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 30868 invoked from network); 15 Dec 2020 23:28:25 -0000 Received: from minnie.tuhs.org (45.79.103.53) by inbox.vuxu.org with ESMTPUTF8; 15 Dec 2020 23:28:25 -0000 Received: by minnie.tuhs.org (Postfix, from userid 112) id 70B1C9C828; Wed, 16 Dec 2020 09:28:15 +1000 (AEST) Received: from minnie.tuhs.org (localhost [127.0.0.1]) by minnie.tuhs.org (Postfix) with ESMTP id 392E49C7BB; Wed, 16 Dec 2020 09:27:47 +1000 (AEST) Authentication-Results: minnie.tuhs.org; dkim=pass (2048-bit key; unprotected) header.d=algebras-org.20150623.gappssmtp.com header.i=@algebras-org.20150623.gappssmtp.com header.b="n/vRclFo"; dkim-atps=neutral Received: by minnie.tuhs.org (Postfix, from userid 112) id D69FA9C7BB; Wed, 16 Dec 2020 09:27:43 +1000 (AEST) Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) by minnie.tuhs.org (Postfix) with ESMTPS id 6F57A9C7B5 for ; Wed, 16 Dec 2020 09:27:42 +1000 (AEST) Received: by mail-lf1-f46.google.com with SMTP id u18so43747356lfd.9 for ; Tue, 15 Dec 2020 15:27:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=algebras-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=xLuaso4gNxQaExDlntu8ZQN9TXypKlZATDskK7kauNQ=; b=n/vRclFotXriQ10+zEgCMHF9Q0No0djVU5GT7PrbVXyKX2bUE8eqoif4TkWFokrQf5 CvZbUjIPIfJxXdhr+PHKDOF3vB2uJ4YXO0S2UQ/KpVFMpXMQeS6RkrMydCDbah68ih8H oKfvc/4u5dhLEGrJA0Jew2f+u1rh67h6V/KYHuUpnIpadGHThACOlgrWz2Buq9k5v/tp 0USOx8nK6GWane5/L+PJrN3y5QB9UQum9ImybX2xu6U+y3bn35E/WFdFyWFU1Wu8JFBx V1HbXyS3tcWTU2zlo4LMVjVJ64nOV+gEA2S3qLkeKC5Mkt5FbxgVAPwuxp4VcZkCZqxr nGHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=xLuaso4gNxQaExDlntu8ZQN9TXypKlZATDskK7kauNQ=; b=LI4mvEhLyfYW7aeJq6mj4AHUj1NjdS0LTtrV2utTVV8+VHepeY2mm3uxAbnWY1I5JW JAUJfRfuV+8VmIS4pLds80otvjoX9JD98oJgLONzsS6h2k1lx5bQ8UXd8fSHuunbMqh2 tnLFFnqpnKDEVyxd8zFjbTb51+LgFHwtsmxcT7M2oeocddcHTsYHMd2E42aowg3oI3cs DzdO33kRBsntjyefWQ+3I8j6FT5LtIWbdEMNJFwN9xbqEvFowofnpjetuPLXX4h5fBCn k0wzo7Siuv0JsnrXuH8fdN839hh5T03xLWIh+OQKm9JzAfu300D+IXQGOotyZRX2JW1b kdEw== X-Gm-Message-State: AOAM530c0krZM3Idchxx0TsD5tOx5R6DsYI4ca3Au7ptOUDbOjYA/7Mk zHgbNHQIvhh/sWhED6O+AqdL6F7LMi3bCAQ7KVgaQdYk0MsS4w== X-Google-Smtp-Source: ABdhPJxi76R1eK7x/p5chUEd1yx6HGeANYhjjPIbi8S7Yd4A/3bHkz67+QBs6GrcHF9MnrVcySZkczznT2f2+qCyOVg= X-Received: by 2002:ac2:5042:: with SMTP id a2mr3938217lfm.42.1608074860181; Tue, 15 Dec 2020 15:27:40 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: George Michaelson Date: Wed, 16 Dec 2020 09:27:28 +1000 Message-ID: To: TUHS main list Content-Type: text/plain; charset="UTF-8" Subject: Re: [TUHS] sh and goto X-BeenThere: tuhs@minnie.tuhs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: The Unix Heritage Society mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: tuhs-bounces@minnie.tuhs.org Sender: "TUHS" HN has a story about a safe bash script template. Putting to one side the oxymoronic qualities of the sentence, the thing which stands out is the use of trap to a function on SIG -Which we all need, but often don't do. Thumping ^C repeatedly when things go unexpectedly wrong, is a fact of life. What do you want your script to do? Coding for the unexpected is just hard. Going into a script (or program) pre-thinking that you have to 'expect the unexpected' breaks the design imperative of planning for success. IF-THEN-ELSE doesn't always cope well with mental models of "do A,B,C but if Z happens get 2 dozen milk" (which leads to the joke about programmers shopping instructions with an IF clause in it) The trap thing in shell always confused me. What state am I "in" when I wind up in that trap? do variables exist (no: IIRC the var=value flow in a shellscript is lazy so the un-instantiated x=y inside an if expression you don't know was reached or not MAY not exist) has sub-job completed, (can trap pre-empt a wait statement? of course it can! what does it mean for children reaping... you do know the PID right?) None of this is rocket surgery. It goes to lawyer-like legalistic "one side of one cow in one field is black" reasoning -which for a program is probably not a bad thing, but it isn't very human(e) thinking for some people. Then enters ^T (the TOPS-10 inherited "what state am I in, in terms of CPU time and I/O") which somebody *else* is dealing with: the thing which called your shell instance.. trap is a setjmp/longjmp type outcome. You pop up in a call you didn't exactly "plan" for (well you did: you wrote it. But you don't know the entry state which led you there, unlike normal program flow) -well, it is.. because you get there. But you aren't going back to your normal logic flow anytime soon in any shellscript I saw.