All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steffen Kothe <steffen.kothe@skothe.de>
To: Saravana Kannan <saravanak@google.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scripts: dev-needs.sh: Enforce bash usage
Date: Thu, 10 Nov 2022 17:48:16 +0000	[thread overview]
Message-ID: <Y205W3kavB5tIDK3@p50> (raw)
In-Reply-To: <CAGETcx9fx3TcgeD+pMyp+LuGfd=hOo5_Weeii2W1Mbd1T2Ua0Q@mail.gmail.com>

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


  reply	other threads:[~2022-11-10 17:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-09 17:03 [PATCH] scripts: dev-needs.sh: Enforce bash usage Steffen Kothe
2022-11-09 22:58 ` Saravana Kannan
2022-11-10 17:48   ` Steffen Kothe [this message]
2022-11-10 19:32     ` Saravana Kannan
2022-11-12  9:41       ` Steffen Kothe
2022-11-14 10:30         ` David Laight
2023-01-25  2:25           ` Saravana Kannan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y205W3kavB5tIDK3@p50 \
    --to=steffen.kothe@skothe.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=saravanak@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.