From owner-freebsd-questions@freebsd.org Thu Dec 5 13:35:27 2019 Return-Path: Delivered-To: freebsd-questions@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 5B3481C9B8B for ; Thu, 5 Dec 2019 13:35:27 +0000 (UTC) (envelope-from rwmaillists@googlemail.com) Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47TGtk3wqnz4CVL for ; Thu, 5 Dec 2019 13:35:26 +0000 (UTC) (envelope-from rwmaillists@googlemail.com) Received: by mail-wr1-x436.google.com with SMTP id q10so3587205wrm.11 for ; Thu, 05 Dec 2019 05:35:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YBmawibosXnQTmXnChwdNOBF7yV7vJaqPU8q+eITtvE=; b=BwsC26kBZHlwxVWGnoEabOhMq+ad13SiCBd8FgKrlEgUO/ozjY1NzKKtNHrbmteLJL PKqfaEeJTWMxcuytIa2SDy+pAbicpSAbNbmx9O6gbFw7/5Zx5AWUnm3eSdRjN6k6Q88E gWX8QgPToSlzS92Nu28LBbvbz8DMiBiHfdFwptVw0m6yTz9//+gDAWPJ+SVdlrDoY/NY aydp6KA0VO7DgLcFEc1pKk8k5lZ31rovPUhQ2grovrIZAZTAmwcfu5x3QpbvTlhKyUQB lra012ktDzDAxMFdlTxhvMc1Tld7y3fP0Gp9i0ybgArPXhLbJPl4zywEtTjxaVt++T0+ eWPw== X-Gm-Message-State: APjAAAXDwouw3wqCNYMYMlVgI4coAGJbqaCjS0edIy9pH+9+dNmaj2GZ Zcn/JQq5eQlLTycj7qlc2D8mBLNL X-Google-Smtp-Source: APXvYqx2bx8BYsDpsAEf8JXvEkFMJ2JIHgugQrNqImhVC8a03FUcuwU2gWDNZrEa+3qgId/T7y+S6Q== X-Received: by 2002:a5d:45c4:: with SMTP id b4mr10056842wrs.303.1575552924356; Thu, 05 Dec 2019 05:35:24 -0800 (PST) Received: from gumby.homeunix.com ([2.219.103.208]) by smtp.gmail.com with ESMTPSA id g21sm14306009wrb.48.2019.12.05.05.35.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2019 05:35:23 -0800 (PST) Date: Thu, 5 Dec 2019 13:35:21 +0000 From: RW To: freebsd-questions@freebsd.org Subject: Re: Counter in sh inside loop, value "encapsulation" Message-ID: <20191205133521.28cb5ac4@gumby.homeunix.com> In-Reply-To: References: <20191204181300.8dd0e03c.freebsd@edvax.de> X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; amd64-portbld-freebsd12.0) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 47TGtk3wqnz4CVL X-Spamd-Bar: -- X-Spamd-Result: default: False [-3.00 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2a00:1450:4000::/36]; FREEMAIL_FROM(0.00)[googlemail.com]; TO_DN_NONE(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[googlemail.com:+]; DMARC_POLICY_ALLOW(-0.50)[googlemail.com,quarantine]; RECEIVED_SPAMHAUS_PBL(0.00)[208.103.219.2.khpj7ygk5idzvmvt5x4ziurxhy.zen.dq.spamhaus.net : 127.0.0.10]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[googlemail.com]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US]; DWL_DNSWL_NONE(0.00)[googlemail.com.dwl.dnswl.org : 127.0.5.0]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; R_DKIM_ALLOW(-0.20)[googlemail.com:s=20161025]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-questions@freebsd.org]; IP_SCORE_FREEMAIL(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; IP_SCORE(0.00)[ip: (-9.15), ipnet: 2a00:1450::/32(-2.69), asn: 15169(-1.93), country: US(-0.05)]; RCVD_IN_DNSWL_NONE(0.00)[6.3.4.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.5.4.1.0.0.a.2.list.dnswl.org : 127.0.5.0]; RCVD_TLS_ALL(0.00)[] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Dec 2019 13:35:27 -0000 On Wed, 4 Dec 2019 20:28:02 -0000 (UTC) Christian Weisgerber wrote: > On 2019-12-04, Polytropon wrote: > > > #!/bin/sh > > COUNT=0 > > grep "^https" ${INFILE} | while read URL; do > > COUNT=`expr ${COUNT} + 1` > > done > > echo "URLs processed: ${COUNT}" # <--- (!) THIS IS ZERO! > > Each command of a pipeline is executed in a subshell. > (Some shells, notably AT&T ksh, behave differently.) > > This is the single most asked shell scripting question. IIRC when this sort of thing came once before someone posted a way of processing the output of a pipeline and having multiple variables directly accessible to the main script. It didn't involve creating files or sockets, or storing the output of the pipeline in a single variable. There was some trick that avoided last stage being done in sub-shell. Unfortunately, I forgot to make a note of it and I haven't been able to find the thread again. Anyone know what it might be?