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_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 16270 invoked from network); 5 Jan 2023 01:53:01 -0000 Received: from minnie.tuhs.org (50.116.15.146) by inbox.vuxu.org with ESMTPUTF8; 5 Jan 2023 01:53:01 -0000 Received: from minnie.tuhs.org (localhost [IPv6:::1]) by minnie.tuhs.org (Postfix) with ESMTP id DAA5042488; Thu, 5 Jan 2023 11:52:37 +1000 (AEST) Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by minnie.tuhs.org (Postfix) with ESMTPS id 91F0E42479 for ; Thu, 5 Jan 2023 11:52:32 +1000 (AEST) Received: by mail-wm1-f46.google.com with SMTP id m8-20020a05600c3b0800b003d96f801c48so294814wms.0 for ; Wed, 04 Jan 2023 17:52:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date:message-id:reply-to; bh=JNbaXlBtw5Q5eQimkieGkNdEnOUePz5ow74DDNxjcf0=; b=IUifeGHkpZFGKwHt+Y92nSWdkStWOZXSWgVA/AWzwh0mmgiQVuh6t3ht3Kecev1TXl x0c5ptFtLKe54oiHcUlPVxmchHSRmflv3VDOQMW/Q6F6RFvvoMjnakwdv+koOUKH2OZs 6jA2H169QjHyEoAcpDCKtTdmfpPHSs82EWidkoeZoeQE54BojZdvvCf/DJVmTY0b4Ki5 ULyMdztPTyp+Jng0wV42PAL2Fp6UgZIYEkiptMYun6ucZNZHyixV2nIfqbOGGiRgsLDh ynhN0sjTDiHW0CjUNqokmkf3QK1S8U0kW+a2ZdTa4bXB3ALGk4WA4En4Qsr+86XpBQzH xjVA== 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:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JNbaXlBtw5Q5eQimkieGkNdEnOUePz5ow74DDNxjcf0=; b=RVOijNBjbK2qRIrmRwRWNSPkJJtob5TG/dMktC3SEGwd+L3HtdV82lWI1iOtSWs3xx gqfzLQLlaVSEAJSVPSOVXWWNAEjrVoHSjQPV5Ewv4IafmNa4DofHQbAdajdOz1rlDGom lqh/Azv/lb0ihxczLqMl90zoHHtKAEHCjcv4ej7AsnVc1cLuLnRqg2KgOSp40mR1duq7 dDrHmQqAQKSBfEcsFeVwW7JTmoJzDaBIiFGs0NhKTzfpkjh9N7waPe8loTQHPiV+kR9T gdvD0BnYsXi24G566c9mxP9VZrZ2ibr0s+r1HuyOA73GfPT+yh0PZMTIK2D2wgBvUV/u dUTw== X-Gm-Message-State: AFqh2krg3hvIid/N3sRNTWQ/MahFib1LOE6zTxFwcArAhaMEmPR2CUeJ 2cnFnnUALHE1HjzXequwqI8= X-Google-Smtp-Source: AMrXdXv+nn/SgHQkHcCXAOtgib/t93rP1mPgXO9xcQ+/hpErHybJVbpVbfuQcti3YvO5NDhyf4gj+g== X-Received: by 2002:a05:600c:15d4:b0:3d1:d746:d95b with SMTP id v20-20020a05600c15d400b003d1d746d95bmr39194998wmf.41.1672883490867; Wed, 04 Jan 2023 17:51:30 -0800 (PST) Received: from [192.168.0.160] ([170.253.36.171]) by smtp.gmail.com with ESMTPSA id bg41-20020a05600c3ca900b003d1e34bcbb2sm661946wmb.13.2023.01.04.17.51.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Jan 2023 17:51:30 -0800 (PST) Sender: Alejandro Colomar Message-ID: Date: Thu, 5 Jan 2023 02:51:28 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Content-Language: en-US To: Adam Thornton , Dan Cross References: From: Alejandro Colomar In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: D5BSHO2IXYYMKIXSDFA6DTOGP5ULMIMF X-Message-ID-Hash: D5BSHO2IXYYMKIXSDFA6DTOGP5ULMIMF X-MailFrom: alx.manpages@gmail.com 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: Douglas McIlroy , TUHS main list X-Mailman-Version: 3.3.6b1 Precedence: list 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 02:29, Adam Thornton wrote: >> On Jan 3, 2023, at 10:26 AM, Dan Cross wrote: >> >> >> A few years ago, I was having lunch with some folks from the Go team >> and one of them remarked, "you shouldn't write a shell script that's >> longer than about 10 lines. Once you do, it's time to rewrite it in a >> real programming language." I was a bit taken aback, but they had a >> point. I'll note that Go standardized on using bash everywhere. I have many counterexamples that take more than 10 lines. I'll show a couple that are very useful to me: # man_section() prints specific manual page sections (DESCRIPTION, SYNOPSIS, # ...) of all manual pages in a directory (or in a single manual page file). # Usage example: .../man-pages$ man_section man2 SYNOPSIS 'SEE ALSO'; man_section() { if [ $# -lt 2 ]; then >&2 echo "Usage: ${FUNCNAME[0]}
..."; return $EX_USAGE; fi local page="$1"; shift; local sect="$*"; find "$page" -type f \ |xargs wc -l \ |grep -v -e '\b1 ' -e '\btotal\b' \ |awk '{ print $2 }' \ |sort \ |while read -r manpage; do (sed -n '/^\.TH/,/^\.SH/{/^\.SH/!p}' <"$manpage"; for s in $sect; do <"$manpage" \ sed -n \ -e "/^\.SH $s/p" \ -e "/^\.SH $s/,/^\.SH/{/^\.SH/!p}"; done;) \ |man -P cat -l - 2>/dev/null; done; } I don't think it's unreadable by being too long, and in every other language it would take a lot more work to implement. And here's another one, which I used a lot until I wrote grepc(1)[1]: # grep_syscall() finds the prototype of a syscall in the kernel sources, # printing the filename, line number, and the prototype. # It should be run from the root of the linux kernel source tree. # Usage example: .../linux$ grep_syscall openat2; # # See also: grepc(1) grep_syscall() { if [ $# -ne 1 ]; then >&2 echo "Usage: ${FUNCNAME[0]} "; return $EX_USAGE; fi find ./* -type f \ |grep '\.c$' \ |xargs grep -l "$1" \ |sort \ |xargs pcregrep -Mn "(?s)^\w*SYSCALL_DEFINE.\($1\b.*?\)" \ |sed -E 's/^[^:]+:[0-9]+:/&\n/'; find ./* -type f \ |grep '\.[ch]$' \ |xargs grep -l "$1" \ |sort \ |xargs pcregrep -Mn "(?s)^asmlinkage\s+[\w\s]+\**sys_$1\s*\(.*?\)" \ |sed -E 's/^[^:]+:[0-9]+:/&\n/'; } Cheers, Alex [1]: > > > My number is larger than 10, but it's smaller than 100.