From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI autolearn=ham autolearn_force=no version=3.4.4 Received: from minnie.tuhs.org (minnie.tuhs.org [50.116.15.146]) by inbox.vuxu.org (Postfix) with ESMTP id 457DE26E89 for ; Sun, 12 May 2024 09:29:15 +0200 (CEST) Received: from minnie.tuhs.org (localhost [IPv6:::1]) by minnie.tuhs.org (Postfix) with ESMTP id 85515434B7; Sun, 12 May 2024 17:29:14 +1000 (AEST) Received: from arjuna.pair.com (arjuna.pair.com [209.68.5.131]) by minnie.tuhs.org (Postfix) with ESMTPS id 3BFD5434B3 for ; Sun, 12 May 2024 17:29:07 +1000 (AEST) Received: from arjuna.pair.com (localhost [127.0.0.1]) by arjuna.pair.com (Postfix) with ESMTP id 48D998A591 for ; Sun, 12 May 2024 03:29:06 -0400 (EDT) Received: from orac.inputplus.co.uk (57.89.115.87.dyn.plus.net [87.115.89.57]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by arjuna.pair.com (Postfix) with ESMTPSA id 08DC68A521 for ; Sun, 12 May 2024 03:29:06 -0400 (EDT) Received: from orac.inputplus.co.uk (orac.inputplus.co.uk [IPv6:::1]) by orac.inputplus.co.uk (Postfix) with ESMTP id DA7E12064E for ; Sun, 12 May 2024 08:29:03 +0100 (BST) From: Ralph Corderoy To: coff@tuhs.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit In-reply-to: <20240511213532.GB8330@mit.edu> References: <20240511213532.GB8330@mit.edu> Date: Sun, 12 May 2024 08:29:03 +0100 Message-Id: <20240512072903.DA7E12064E@orac.inputplus.co.uk> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inputplus.co.uk; h=from:to:subject:mime-version:content-type:content-transfer-encoding:in-reply-to:references:date:message-id; s=pair-202402161033; bh=7hJdBkFCi2RJMmowvaS9axz/eFdciOgK8pWzamFRK+s=; b=b9qYhP/Eeg3aQkz+C/X9/EB7F4Ne5sSV0t/oN1cVTubVBQO3gn+85rbZ66cz4VROaTGRrK/YZ5mGCvgGkhPwMR/jK2JSUL6Zk4pzofne/QHfr/y2GVYiJ7/HhTHTYcPXfM/NBryIsXQUi6HUHWXDrLov+JuxnWQ9x21MZsaACwdE1XrJMem8Cri/R6SUTvrPRKDuUPvSohrnPmnn6QDWUvuZy8PR4RK3WeHmsqN2PDXZnjThSAbFBUSJlqHwO9DqSTlQhEqRY8Ln1yPuURuZR0gh8o2nTY2qhf2XawlPVWK+TXeO0AfPz4fg4EH5JbJ80joUSyrgQqp6wlUbeKJC+g== X-Scanned-By: mailmunge 3.11 on 209.68.5.131 Message-ID-Hash: 7QYV7CGTDY5KM4LSQHOV5KGSCKDMQP3P X-Message-ID-Hash: 7QYV7CGTDY5KM4LSQHOV5KGSCKDMQP3P X-MailFrom: ralph@inputplus.co.uk X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.6b1 Precedence: list Subject: [COFF] Re: On Bloat and the Idea of Small Specialized Tools List-Id: Computer Old Farts Forum Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Hi, As an example of pushing the limit of Unix pipes, I found this awkward to read, e.g. the noise of the redundant backslash after an end-of-line pipe. > gcloud compute instances describe \ > --zone "$z" "$i" --format=json > "$inst_info" > kver=$(jq < "$inst_info" 2> /dev/null \ > '.metadata.items[] | select(.key == "kernel_version") | .value' | \ > sed -e 's/^"//' -e 's/"$//' \ > -e 's/^Linux xfstests-[0-9A-Za-z-]* //' -e 's/ .*//') > ` gce_status=$(jq < "$inst_info" .status | \ > sed -e 's/^"//' -e 's/"$//') > status=$(jq < "$inst_info" 2> /dev/null \ > '.metadata.items[] | select(.key == "status") | .value' | \ > sed -e 's/^"//' -e 's/"$//') > ip=$(jq < "$inst_info" 2> /dev/null \ > '.networkInterfaces[] | .accessConfigs[] | select(.name == "external-nat") | .natIP' | \ > sed -e 's/^"//' -e 's/"$//') Re-formatting, including the more idiomatic placement of I/O redirection, gives gcloud compute instances describe \ --zone "$z" "$i" --format=json >"$inst_info" kver=$( jq '.metadata.items[] | select(.key == "kernel_version") | .value' \ <"$inst_info" 2>/dev/null | sed ' s/^"//; s/"$// s/^Linux xfstests-[0-9A-Za-z-]* // s/ .*// ' ) gce_status=$( jq .status \ <"$inst_info" | sed 's/^"//; s/"$//' ) status=$( jq '.metadata.items[] | select(.key == "status") | .value' \ <"$inst_info" 2>/dev/null | sed 's/^"//; s/"$//' ) ip=$( jq '.networkInterfaces[] | .accessConfigs[] | select(.name == "external-nat") | .natIP' \ <"$inst_info" 2>/dev/null | sed 's/^"//; s/"$//' ) The repetition is now more clear to me. And I see jq's stderr is discarded in all but one case. Assuming that one can be, or should be, the same allows factoring. gcloud compute instances describe \ --zone "$z" "$i" --format=json >"$inst_info" query() { jq "${1?}" <"$inst_info" 2>/dev/null | sed 's/^"//; s/"$//' } kver=$( query '.metadata.items[] | select(.key == "kernel_version") | .value' | sed 's/^Linux xfstests-[0-9A-Za-z-]* //; s/ .*//' ) gce_status=$(query .status) status=$(query '.metadata.items[] | select(.key == "status") | .value') ip=$(query '.networkInterfaces[] | .accessConfigs[] | select(.name == "external-nat") | .natIP') -- Cheers, Ralph.