Message ID | 20221109170341.36785-1-steffen.kothe@skothe.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp459713wru; Wed, 9 Nov 2022 09:18:06 -0800 (PST) X-Google-Smtp-Source: AMsMyM5nnHXCie0RAQryjZBY4kbuNY/I99bRvKPj335rFmHHvQOAfCdVGFsN54T5GM4RV4nSpfe/ X-Received: by 2002:a17:907:70a:b0:750:bf91:caa3 with SMTP id xb10-20020a170907070a00b00750bf91caa3mr58025945ejb.711.1668014286435; Wed, 09 Nov 2022 09:18:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668014286; cv=none; d=google.com; s=arc-20160816; b=uIUnmGAF6MSzkb4KQBOwGrjFfmxnGzbz2wVzSl15kqKV2RGeBEzhV849ooGeT/G7s8 C7bz9Cp7Kskz25DgK5hdhQ6yJil9IN+ZmnWmDSLL7jb97cMA+47T6VDpMzB58X6vTElC ZTKp9FEn4UqZgXQ+DG7qvhigNEgSNa4Jjh13A+/X3/r09+gny36yhTDY75oiR8monls2 wn18aK7ihJGxarNT6mhEBog59h37h1qnNOUnyWe2jYScejN47D2MPWPu4vVaxx3sdijT 0zgJqXp1SdCYimvTW6rq153NmCAEW4OOfQ+qfyxOWMp3s+J1rXFw/sROhp0liic9BOXx /Wrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:message-id:subject:cc:from:to:dkim-signature:date; bh=XedvgB1po9ayTY4ox9EA0HdN+W+EAwbhCury97jYShU=; b=lNF/wqOO7u0TgmiD6rJOv4oA9tmgf5k+NvzSbm2J2oA+1DHC4lG1eonYoM/Rz1aGUw r+Msmyad+eRjQQh7qVJoPHyzZ+EfYluDAujMgHlCHOBbsnKigbbIwtFULG7AwsHh7/Y8 WDuzicg431k7o+B/fX5h318CAzZ6gJr+28MkyO5Bg/1qt92gD2ZTHKeb70557dOaSGXv OT0vWQuLUk0IKyz2qWa4CikWiivm3nzLYeIMUa2ZS2hyYywtnNeIcm4QLSxDQvg257ZP cRikoXSn6jLG+nb7YVKQECfK4UEURRL9V4Ao0kt19pBLwouSXBOkg8qBsxGxJ9yenV5H 7ayw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@skothe.de header.s=protonmail header.b=cRqMj1th; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=skothe.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ne28-20020a1709077b9c00b007a9c3366e9asi17032048ejc.716.2022.11.09.09.17.42; Wed, 09 Nov 2022 09:18:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@skothe.de header.s=protonmail header.b=cRqMj1th; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=skothe.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231601AbiKIRFO (ORCPT <rfc822;dexuan.linux@gmail.com> + 99 others); Wed, 9 Nov 2022 12:05:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231765AbiKIRE4 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 9 Nov 2022 12:04:56 -0500 Received: from mail-4317.proton.ch (mail-4317.proton.ch [185.70.43.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AA7B2A277 for <linux-kernel@vger.kernel.org>; Wed, 9 Nov 2022 09:04:11 -0800 (PST) Date: Wed, 09 Nov 2022 17:03:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skothe.de; s=protonmail; t=1668013448; x=1668272648; bh=XedvgB1po9ayTY4ox9EA0HdN+W+EAwbhCury97jYShU=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=cRqMj1thG607FtQz4kSbRmrrOx+Rn91jHa29eD6KyI47xALpzxLwsY5eKOBCOO0L1 Gj3C3xBiN8QKu30scFJ4HJGgNn4DNjrhuCso3NWx/z1UNNMl4iPvaD3MVtOVFH+tQO OIetxpI7IUdXMSt5GwqogQX2rRwfAfBEPFS+V0cN2Xi7KM6+JKX0xmrI3y2iQUmjkQ JZ1GYdV1zEyG77ovLy2oHInlb+3xsiOW82vgOc6NdAeqB4YOZMmX5skng5XRxsLlDR hKsKIxwKb3OXOIjZmhvqKh3t7gPPIUXk06eaxrRG3BPZo5on6+U2PLQcCdr4UxkAMw hTz48g77W4LgA== To: saravanak@google.com From: Steffen Kothe <steffen.kothe@skothe.de> Cc: linux-kernel@vger.kernel.org, Steffen Kothe <steffen.kothe@skothe.de> Subject: [PATCH] scripts: dev-needs.sh: Enforce bash usage Message-ID: <20221109170341.36785-1-steffen.kothe@skothe.de> Feedback-ID: 55345914:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749039748700260322?= X-GMAIL-MSGID: =?utf-8?q?1749039748700260322?= |
Series |
scripts: dev-needs.sh: Enforce bash usage
|
|
Commit Message
Steffen Kothe
Nov. 9, 2022, 5:03 p.m. UTC
Calling the script from a system which does not invoke bash
by default causes a return with a syntax error like:
./dev-needs.sh: 6: Syntax error: "(" unexpected
/bin/sh invokes on most distributions a symbolic link to a
default shell like dash (Debian) or bash (Ubuntu).
Since the script depends on bash syntax, enforce the same by
default to prevent syntax errors caused by wrong shell type usage.
Signed-off-by: Steffen Kothe <steffen.kothe@skothe.de>
---
scripts/dev-needs.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--
2.30.2
Comments
On Wed, Nov 9, 2022 at 9:04 AM Steffen Kothe <steffen.kothe@skothe.de> wrote: > > Calling the script from a system which does not invoke bash > by default causes a return with a syntax error like: > > ./dev-needs.sh: 6: Syntax error: "(" unexpected > > /bin/sh invokes on most distributions a symbolic link to a > default shell like dash (Debian) or bash (Ubuntu). > > Since the script depends on bash syntax, enforce the same by > default to prevent syntax errors caused by wrong shell type usage. I wrote this so that it can run on an Android target that runs toybox. Sadly toybox doesn't like have /bin/bash. This will break my use case. So I'll have to Nak this. I'm open to other ideas though as I'd like to this to work in as many cases as possible. Should we just add a wrapper that has /bin/bash and then sources this file? Also looks like multiple #! lines aren't supported by bash, so we can't add multiple lines either. -Saravana > > Signed-off-by: Steffen Kothe <steffen.kothe@skothe.de> > --- > scripts/dev-needs.sh | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/scripts/dev-needs.sh b/scripts/dev-needs.sh > index 454cc304fb448..46537859727bc 100755 > --- a/scripts/dev-needs.sh > +++ b/scripts/dev-needs.sh > @@ -1,4 +1,4 @@ > -#! /bin/sh > +#! /bin/bash > # SPDX-License-Identifier: GPL-2.0 > # Copyright (c) 2020, Google LLC. All rights reserved. > # Author: Saravana Kannan <saravanak@google.com> > -- > 2.30.2 > >
Am Wed, Nov 09, 2022 at 02:58:15PM -0800 schrieb Saravana Kannan: > On Wed, Nov 9, 2022 at 9:04 AM Steffen Kothe <steffen.kothe@skothe.de> wrote: > > > > Calling the script from a system which does not invoke bash > > by default causes a return with a syntax error like: > > > > ./dev-needs.sh: 6: Syntax error: "(" unexpected > > > > /bin/sh invokes on most distributions a symbolic link to a > > default shell like dash (Debian) or bash (Ubuntu). > > > > Since the script depends on bash syntax, enforce the same by > > default to prevent syntax errors caused by wrong shell type usage. > > I wrote this so that it can run on an Android target that runs toybox. > Sadly toybox doesn't like have /bin/bash. This will break my use case. > So I'll have to Nak this. Ok, I see. > I'm open to other ideas though as I'd like to this to work in as many > cases as possible. Should we just add a wrapper that has /bin/bash and > then sources this file? I mean, we could leave at least a warning on top above the first function via a simple echo. Sth. like: echo "Warning: $0 is only tested for following shell variants [toybox, bash]. Other shells might be not following the specific syntax of this script." echo "Shell is: $(readlink /bin/sh)" I would prevent to add another wrapper to it, because its fairly easy to cp this file to a target. An embedded system with a pure POSIX compliant shell will never be compatible to this kind of syntax. What do you think about a more describing approach of the error instead of handling it with some weird logic and wrapping? Cheers, skothe > Also looks like multiple #! lines aren't supported by bash, so we > can't add multiple lines either. > > -Saravana > > > > > Signed-off-by: Steffen Kothe <steffen.kothe@skothe.de> > > --- > > scripts/dev-needs.sh | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/scripts/dev-needs.sh b/scripts/dev-needs.sh > > index 454cc304fb448..46537859727bc 100755 > > --- a/scripts/dev-needs.sh > > +++ b/scripts/dev-needs.sh > > @@ -1,4 +1,4 @@ > > -#! /bin/sh > > +#! /bin/bash > > # SPDX-License-Identifier: GPL-2.0 > > # Copyright (c) 2020, Google LLC. All rights reserved. > > # Author: Saravana Kannan <saravanak@google.com> > > -- > > 2.30.2 > > > > -- Cheers, Steffen
On Thu, Nov 10, 2022 at 9:48 AM Steffen Kothe <steffen.kothe@skothe.de> wrote: > > Am Wed, Nov 09, 2022 at 02:58:15PM -0800 schrieb Saravana Kannan: > > On Wed, Nov 9, 2022 at 9:04 AM Steffen Kothe <steffen.kothe@skothe.de> wrote: > > > > > > Calling the script from a system which does not invoke bash > > > by default causes a return with a syntax error like: > > > > > > ./dev-needs.sh: 6: Syntax error: "(" unexpected > > > > > > /bin/sh invokes on most distributions a symbolic link to a > > > default shell like dash (Debian) or bash (Ubuntu). > > > > > > Since the script depends on bash syntax, enforce the same by > > > default to prevent syntax errors caused by wrong shell type usage. > > > > I wrote this so that it can run on an Android target that runs toybox. > > Sadly toybox doesn't like have /bin/bash. This will break my use case. > > So I'll have to Nak this. > > Ok, I see. > > > I'm open to other ideas though as I'd like to this to work in as many > > cases as possible. Should we just add a wrapper that has /bin/bash and > > then sources this file? > > I mean, we could leave at least a warning on top above the first > function via a simple echo. > > Sth. like: > > echo "Warning: $0 is only tested for following shell variants > [toybox, bash]. Other shells might be not following the > specific syntax of this script." > > echo "Shell is: $(readlink /bin/sh)" > > I would prevent to add another wrapper to it, because its fairly easy > to cp this file to a target. An embedded system with a pure POSIX compliant > shell will never be compatible to this kind of syntax. > > What do you think about a more describing approach of the error instead > of handling it with some weird logic and wrapping? Are you suggesting we check for the shell being toybox/bash and then printing this? Always printing it isn't nice because it'll mess up all the script that expect the output to be just what it is today. But if you want to add an error check, I'm okay with that. -Saravana > > Cheers, > skothe > > > Also looks like multiple #! lines aren't supported by bash, so we > > can't add multiple lines either. > > > > -Saravana > > > > > > > > Signed-off-by: Steffen Kothe <steffen.kothe@skothe.de> > > > --- > > > scripts/dev-needs.sh | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/scripts/dev-needs.sh b/scripts/dev-needs.sh > > > index 454cc304fb448..46537859727bc 100755 > > > --- a/scripts/dev-needs.sh > > > +++ b/scripts/dev-needs.sh > > > @@ -1,4 +1,4 @@ > > > -#! /bin/sh > > > +#! /bin/bash > > > # SPDX-License-Identifier: GPL-2.0 > > > # Copyright (c) 2020, Google LLC. All rights reserved. > > > # Author: Saravana Kannan <saravanak@google.com> > > > -- > > > 2.30.2 > > > > > > > > -- > Cheers, > Steffen >
Am Thu, Nov 10, 2022 at 11:32:12AM -0800 schrieb Saravana Kannan: > On Thu, Nov 10, 2022 at 9:48 AM Steffen Kothe <steffen.kothe@skothe.de> wrote: > > > > Am Wed, Nov 09, 2022 at 02:58:15PM -0800 schrieb Saravana Kannan: > > > On Wed, Nov 9, 2022 at 9:04 AM Steffen Kothe <steffen.kothe@skothe.de> wrote: > > > > > > > > Calling the script from a system which does not invoke bash > > > > by default causes a return with a syntax error like: > > > > > > > > ./dev-needs.sh: 6: Syntax error: "(" unexpected > > > > > > > > /bin/sh invokes on most distributions a symbolic link to a > > > > default shell like dash (Debian) or bash (Ubuntu). > > > > > > > > Since the script depends on bash syntax, enforce the same by > > > > default to prevent syntax errors caused by wrong shell type usage. > > > > > > I wrote this so that it can run on an Android target that runs toybox. > > > Sadly toybox doesn't like have /bin/bash. This will break my use case. > > > So I'll have to Nak this. > > > > Ok, I see. > > > > > I'm open to other ideas though as I'd like to this to work in as many > > > cases as possible. Should we just add a wrapper that has /bin/bash and > > > then sources this file? > > > > I mean, we could leave at least a warning on top above the first > > function via a simple echo. > > > > Sth. like: > > > > echo "Warning: $0 is only tested for following shell variants > > [toybox, bash]. Other shells might be not following the > > specific syntax of this script." > > > > echo "Shell is: $(readlink /bin/sh)" > > > > I would prevent to add another wrapper to it, because its fairly easy > > to cp this file to a target. An embedded system with a pure POSIX compliant > > shell will never be compatible to this kind of syntax. > > > > What do you think about a more describing approach of the error instead > > of handling it with some weird logic and wrapping? > > Are you suggesting we check for the shell being toybox/bash and then > printing this? Always printing it isn't nice because it'll mess up all > the script that expect the output to be just what it is today. > > But if you want to add an error check, I'm okay with that. What about a re-write of the script in POSIX compliant style? This should work then in every shell derivate without weird checks. This would remove for example function declarations, arrays and so on, targeting to the same printable output but with different logic in the background. > -Saravana > > > > > Cheers, > > skothe > > > > > Also looks like multiple #! lines aren't supported by bash, so we > > > can't add multiple lines either. > > > > > > -Saravana > > > > > > > > > > > Signed-off-by: Steffen Kothe <steffen.kothe@skothe.de> > > > > --- > > > > scripts/dev-needs.sh | 2 +- > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > diff --git a/scripts/dev-needs.sh b/scripts/dev-needs.sh > > > > index 454cc304fb448..46537859727bc 100755 > > > > --- a/scripts/dev-needs.sh > > > > +++ b/scripts/dev-needs.sh > > > > @@ -1,4 +1,4 @@ > > > > -#! /bin/sh > > > > +#! /bin/bash > > > > # SPDX-License-Identifier: GPL-2.0 > > > > # Copyright (c) 2020, Google LLC. All rights reserved. > > > > # Author: Saravana Kannan <saravanak@google.com> > > > > -- > > > > 2.30.2 > > > > > > > > > > > > -- > > Cheers, > > Steffen > > -- Cheers, Steffen
From: Steffen Kothe > Sent: 12 November 2022 09:41 ... > What about a re-write of the script in POSIX compliant style? This > should work then in every shell derivate without weird checks. > > This would remove for example function declarations, arrays and so on, > targeting to the same printable output but with different logic in the > background. A quick read: - remove the word 'function'. - remove all 'local', ensure names are unique. - use 'printf '%s' "....." instead of echo -n. That should be pretty near portable. Some shells that don't object to the 'local' keyword don't actually implement local variables! David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
On Mon, Nov 14, 2022 at 2:30 AM David Laight <David.Laight@aculab.com> wrote: > > From: Steffen Kothe > > Sent: 12 November 2022 09:41 > ... > > What about a re-write of the script in POSIX compliant style? This > > should work then in every shell derivate without weird checks. > > > > This would remove for example function declarations, arrays and so on, > > targeting to the same printable output but with different logic in the > > background. > > A quick read: > > - remove the word 'function'. > - remove all 'local', ensure names are unique. > - use 'printf '%s' "....." instead of echo -n. > > That should be pretty near portable. > Some shells that don't object to the 'local' keyword don't > actually implement local variables! > Steffen/David, I'll happily test and take any updates that's at least as readable as what's there now, as long as it continues working with toybox. -Saravana
diff --git a/scripts/dev-needs.sh b/scripts/dev-needs.sh index 454cc304fb448..46537859727bc 100755 --- a/scripts/dev-needs.sh +++ b/scripts/dev-needs.sh @@ -1,4 +1,4 @@ -#! /bin/sh +#! /bin/bash # SPDX-License-Identifier: GPL-2.0 # Copyright (c) 2020, Google LLC. All rights reserved. # Author: Saravana Kannan <saravanak@google.com>