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=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 486 invoked from network); 4 Jan 2023 19:33:29 -0000 Received: from minnie.tuhs.org (50.116.15.146) by inbox.vuxu.org with ESMTPUTF8; 4 Jan 2023 19:33:29 -0000 Received: from minnie.tuhs.org (localhost [IPv6:::1]) by minnie.tuhs.org (Postfix) with ESMTP id DF9054248F; Thu, 5 Jan 2023 05:33:22 +1000 (AEST) Received: from mpv-out-cfd-1.case.edu (mpv-out-cfd-1.CWRU.Edu [129.22.103.196]) by minnie.tuhs.org (Postfix) with ESMTPS id 066984248C for ; Thu, 5 Jan 2023 05:33:17 +1000 (AEST) Received: from mpv-local-cfd-1.CWRU.Edu (EHLO mpv-local-cfd-1.case.edu) ([129.22.103.203]) by mpv-out-cfd-1.case.edu (MOS 4.4.8-GA FastPath queued) with ESMTP id AHQ35514; Wed, 04 Jan 2023 14:33:16 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=smtp-primary; t=1672860796; bh=2wAqSHQVP8oUdUda1Bc3kSsmST0c0s2609hgqbgpis8=; l=2154; h=Message-ID:Date:MIME-Version:Reply-To:Cc:Subject:To:References: From:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=sAuEyfBY5S2nYaXMMZXFwPVnzaQDd4RMmcwRdISaABONpfd3UrdGdWu+vNbESB7J5n 3SSbbIP9cyN4Y9ta+w5mY66EJpU1n4vxLuYsKO09LT9ZYL/wiG3n5iHaN7uFNj/ox4F SNyrthDr99XV1Wm9KWvd+a+NAEef0m4fkLPXtDUbcgNNBYWPjlWbgw9U87GNVy3qK8u 32QI6Ip+5cJEakokzzZVp2cVcAOGFltx0MGu0ppPzepWmTIPei2qxFNIDubOtAGqWFo NcSajJWfKjrIvobg3r58n2tdrWG/3I2ljBUQuDuTthuGoLdF/J16PR7vmxMqzmMTnF7 zU0tDwTA== Received: from mail-qk1-f199.google.com (EHLO mail-qk1-f199.google.com) ([209.85.222.199]) by mpv-local-cfd-1.case.edu (MOS 4.4.8-GA FastPath queued) with ESMTP id AQF44306; Wed, 04 Jan 2023 14:33:16 -0500 (EST) Received: by mail-qk1-f199.google.com with SMTP id bp6-20020a05620a458600b006ffd3762e78so23767885qkb.13 for ; Wed, 04 Jan 2023 11:33:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=g-case; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:cc:reply-to:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=2wAqSHQVP8oUdUda1Bc3kSsmST0c0s2609hgqbgpis8=; b=JsfXDqxAu86/UtqlJGbowfB5hoAf7hBSICeXfTW0ZcB4Kl2f21v7a3bkZrq1+vXoj5 wqvcbHHMqdCkCkjEtruZrgnQT5CEprfdo8MiWuEiJDAdchF6m+Jxi8hR3dqY+ZOaIpU6 wapQ4JwkP7wo9/pde5rLgF04rHaB4oGiqLsKoRCD1ps9gZjLSFmK9wm3HBg7ubnnpwp5 YwRDswMLs/+cyswOCc4aOQWWuNDiAdmLlTQc4QkgF5xWWAEt36SvU2vCXQswYkXbxSa1 VcjPUcfCEjlXIgppjkO/NGaGUMRKNUn6shnl69HyQouUK7FmSeTlD18Q2PdirdPhv5aM nTfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:cc:reply-to:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2wAqSHQVP8oUdUda1Bc3kSsmST0c0s2609hgqbgpis8=; b=44CqTqNlZUBoHwB22snoizZ/eUxMUeZ4bFoUEt//DPCrT4h5GG2BEw9W/Y6rcRjgLv NJ4njO4bqXPO9trUQa5rD4ERXHLRvnIUxsExHlxC6Ebwte5U4lDLZAp6zuxuVuOCUQlf Oy0YdUnmwKCAxe7aXmTtxplP9D8Kgs2X/DuABhUi97rPzJgsvxbrtVplGru/D4pr3eEI /mvBoatVyPpSgBtD+mXbNiVks6KPpHOmyL8pGUTkW+JaDawK+Fv3TCEfySlcajXFWis/ SxcIjo9pXE7yJwh0nItSL0x++2wCMBC4Wpzr+i7twDaUYeQtbrFrNjaV7fhWKQEDYyEL k9Kw== X-Gm-Message-State: AFqh2krtl/OeGJEdaOnWSzrhm3wNq8hWLURqtN0GlEhuVYft2KaKfrqj +XKEMKCmi9ZWCZM79RT73RKVfoOBNi3BAM5o/Hd706670pnfNIYXVO142/ejt9uicAUWMxpU6ga pigtpY/g= X-Received: by 2002:ac8:4e04:0:b0:3ab:5dc7:6bf0 with SMTP id c4-20020ac84e04000000b003ab5dc76bf0mr66416937qtw.36.1672860795542; Wed, 04 Jan 2023 11:33:15 -0800 (PST) X-Google-Smtp-Source: AMrXdXuMhOL0vZ7+vwW88B+WkNRVw0wXXVNM5Tw42i/voHeu+k8XQjuFRqDuY97IfsddlPNmsX5atQ== X-Received: by 2002:ac8:4e04:0:b0:3ab:5dc7:6bf0 with SMTP id c4-20020ac84e04000000b003ab5dc76bf0mr66416918qtw.36.1672860795276; Wed, 04 Jan 2023 11:33:15 -0800 (PST) Received: from [129.22.8.211] (caleb.INS.CWRU.Edu. [129.22.8.211]) by smtp.gmail.com with ESMTPSA id cn5-20020a05622a248500b003434d3b5938sm20915798qtb.2.2023.01.04.11.33.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Jan 2023 11:33:14 -0800 (PST) Message-ID: <52d3239f-f9a5-02c2-1a75-e74364d0590f@case.edu> Date: Wed, 4 Jan 2023 14:33:13 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Content-Language: en-US To: Dan Cross , Bakul Shah References: <52FB6638-AEFF-4A4F-8C2E-32089D577BA0@planet.nl> <464819f0-d2f6-2a60-6481-a194f4428b4d@case.edu> <20221230200246.GW5825@mcvoy.com> <88f83b4c-b3f9-ed87-b2fa-560fb369742a@makerlisp.com> <20221231035931.GG5825@mcvoy.com> <528f0c53-ccc2-88a1-5a7b-120362c648dd@mhorton.net> <20230102165120.GK25547@mcvoy.com> <20230102174304.GM25547@mcvoy.com> From: Chet Ramey In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Mirapoint-IP-Reputation: reputation=Good-1, source=Queried, refid=tid=0001.0A742F92.63B5D153.0032, actions=tag X-Mirapoint-IP-Reputation: reputation=good-1, source=Fixed, refid=n/a, actions=tag X-Junkmail-Status: score=8/90, host=mpv-out-cfd-1.case.edu X-Junkmail-PrAS-Raw: score=8/90, refid=2.7.2:2023.1.4.191225:17:8.907, ip=, rules=__YOUTUBE_RCVD, DKIM_SIGNATURE, __X_GOOGLE_DKIM_SIGNATURE, __X_GM_MESSAGE_STATE, __X_GOOGLE_SMTP_SOURCE, __HAS_MSGID, __SANE_MSGID, __MSGID_HEX_844412, DATE_TZ_NA, __MIME_VERSION, __USER_AGENT, __MOZILLA_USER_AGENT, __HAS_REPLYTO, __HAS_CC_HDR, __MULTIPLE_RCPTS_CC_X2, __CC_NAME, __CC_NAME_DIFF_FROM_ACC, __SUBJ_REPLY, __BOUNCE_CHALLENGE_SUBJ, __BOUNCE_NDR_SUBJ_EXEMPT, __SUBJ_ALPHA_END, __TO_MALFORMED_2, __MULTIPLE_RCPTS_TO_X2, __TO_NAME, __TO_NAME_DIFF_FROM_ACC, __HAS_REFERENCES, __REFERENCES, __HAS_FROM, FROM_EDU_TLD, __IN_REP_TO, __CT, __CT_TEXT_PLAIN, __CTE, CTE_7BIT, __REPLYTO_SAMEAS_FROM_ADDY, __REPLYTO_SAMEAS_FROM_ACC, __RCPT_DOMAIN_NOT_TO, __REPLYTO_SAMEAS_FROM_DOMAIN, __DKIM_ALIGNS_1, __DKIM_ALIGNS_2, __FUR_HEADER, __ANY_URI, __URI_MAILTO, __URI_WITH_PATH, __URI_ENDS_IN_SLASH, __FRAUD_BODY_WEBMAIL, __URI_NO_WWW, __CP_URI_IN_BODY, [TRUNCATED], so=2010-03-03 19:42:08, dmn=2016-08-03-0138 Message-ID-Hash: BZIIBVFLV67Y7E2JHYHMNPNMA5K2NE27 X-Message-ID-Hash: BZIIBVFLV67Y7E2JHYHMNPNMA5K2NE27 X-MailFrom: chet.ramey@case.edu X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-tuhs.tuhs.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: The Eunuchs Hysterical Society X-Mailman-Version: 3.3.6b1 Precedence: list Reply-To: chet.ramey@case.edu Subject: [TUHS] Re: A few comments on porting the Bourne shell List-Id: The Unix Heritage Society mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 1/4/23 11:15 AM, Dan Cross wrote: > On Tue, Jan 3, 2023 at 11:16 PM Bakul Shah wrote: >> On Jan 3, 2023, at 7:31 PM, Dan Cross wrote: >>> On Tue, Jan 3, 2023 at 10:22 PM John Cowan wrote: >>>> Making shell scripts portable means not using pipelines, because given "foo | bar", kshNN and zsh execute foo in a subshell and bar in the top-level shell, whereas in other shells, both foo and bar execute in subshells. (For this reason, Posix allows either behavior.) Not having pipelines is a pretty drastic limitation. >>> >>> This came up at work just the other day: >>> >>> echo ' hi ' | sed 's/^ *//;s/ *$//' | read bummer >>> echo $bummer >>> >>> The behavior varies between ksh, zsh, bash, sh. Yay. >> >> On this example sh, zsh, bash behave the same way on >> freebsd. Rather than ban |, I think the lesson is to >> *avoid* builtin commands in a pipeline that can affect >> shell's environment. I only write /bin/sh scripts in >> any case. > > Interesting. In my testing, `bash` was the odd man out: > > : doctor; zsh > : doctor; echo ' hi ' | sed 's/^ *//;s/ *$//' | read bummer > echo $bummer > > hi > : doctor; > : doctor; bash > : doctor; echo ' hi ' | sed 's/^ *//;s/ *$//' | read bummer > echo $bummer > > : doctor; > exit > : doctor; ksh > : doctor; echo ' hi ' | sed 's/^ *//;s/ *$//' | read bummer > : doctor; echo $bummer > hi > : doctor; > : doctor; sh > : doctor; echo ' hi ' | sed 's/^ *//;s/ *$//' | read bummer > : doctor; echo $bummer > hi > : doctor; > : doctor; > > That's on illumos. On Illumos, /bin/sh and /usr/xpg4/bin/sh are both links to ksh93. ksh88/ksh93 and zsh are the only shells that unconditionally run the last element of a pipeline in the current shell. Bash will do it if job control is not enabled and the `lastpipe' option is enabled. It's usually not a problem, but you do have to be aware of potential side effects. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/