Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14502

Re: Assignment of $* to a var removes spaces on unset IFS.

Path csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From Bize Ma <binaryzebra@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: Assignment of $* to a var removes spaces on unset IFS.
Date Wed, 15 Aug 2018 11:54:30 -0400
Lines 172
Approved bug-bash@gnu.org
Message-ID <mailman.5152.1534360408.1292.bug-bash@gnu.org> (permalink)
References <CAFra36i0MReG0Sk8m11BMeqPD+TNRLgOsTSGQ4x0uDD20Z0v6w@mail.gmail.com> <20180815124455.ta5t6orhy3csgh4y@eeg.ccf.org>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
X-Trace usenet.stanford.edu 1534360409 21041 208.118.235.17 (15 Aug 2018 19:13:29 GMT)
X-Complaints-To action@cs.stanford.edu
Cc bug-bash <bug-bash@gnu.org>
To Greg Wooledge <wooledg@eeg.ccf.org>
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=+1PlngIZ4EWWU7aaxvLAaCk33dXPlmDqVaxPLkLYyL8=; b=akHxbOoikiwh+mpTcO7SNS5nWILAO7kX9RqXT1ncgCbTro0c7lb9ZX6liRYHQgNnVh sduILVGiIrjXjmcxo85D6zGcXOQygPGPgShoXBvs8m2TiSAGZ74MbqCrX/pjfHCIHM+f Mkvd3/4Th8+yPAaPvgcQRgW3uWpIu7/GY7Ff0JYnU6ypAZ6iSdHszXxTT1GwSac1CEM4 uqSg4CmHhnFpoQhzCTKXL9ecDeEWPo9oUGo+JARnCCPqrnV4p+a3WYPnIoKmeEdNAnzo wP8tbM8xCdpAr0hjgExzakLylkM8YKKeL/3ZvEy46maNkLxKPTqK7Ig7ozgmFJBD43Q3 7o1g==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=+1PlngIZ4EWWU7aaxvLAaCk33dXPlmDqVaxPLkLYyL8=; b=ocuKzmTfOZUY5+2xhI3ThwBZQ4KRNVVX2J+cznmDKzJEz1nnBoAvmoa0sqqvDY4WdN 0K9oGqHfFe0dHN9Cb0ZLDEImhTEGiCVV+QNE1c1qGZ+OUis2KU0itttS3n/NYQN8Owsq vE+kCZyMZoOMWCEkmBePVBB50SYcpQSqXK8/nFt2h95kDMHoB1Y8YE1aXDlNazSOCkaZ rRh2FOam1LztROjcGHsKPfTBey06e6SNw4vit47x2YOEs1VKnB1fcOjyHZ10Q+Bo5ycq qmZx2EqxCaQvc34IQK1ZoT64A2a+PsLLxbMIVoiZ4lAY99/PM/JoPvCC4biieEcCwwj+ 8e1A==
X-Gm-Message-State AOUpUlHesGe1aM00hdz0TpRe8E+Pdp0k+ACYQjFrn5WqdhLqOkAQdAtO MFXIje9SnSr3Xpy7seyNimR8KF/S+356cxI8cGc=
X-Google-Smtp-Source AA+uWPx4O6oODp+OANSfLM5rsmZLxBL4uil82ipwCwvELk8+FxtqvrMXRteJRYSnEBrS0e+Xw3rWS2vIDYzJWPBaWiY=
X-Received by 2002:aca:c602:: with SMTP id w2-v6mr29292596oif.122.1534348471001; Wed, 15 Aug 2018 08:54:31 -0700 (PDT)
In-Reply-To <20180815124455.ta5t6orhy3csgh4y@eeg.ccf.org>
X-detected-operating-system by eggs.gnu.org: Genre and OS details not recognized.
X-Received-From 2607:f8b0:4003:c06::22a
X-Content-Filtered-By Mailman/MimeDel 2.1.21
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.21
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <http://lists.gnu.org/archive/html/bug-bash/>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
Xref csiph.com gnu.bash.bug:14502

Show key headers only | View raw


2018-08-15 8:44 GMT-04:00 Greg Wooledge <wooledg@eeg.ccf.org>:

> This reply was sent to me without Cc-ing the list.  I have added the Cc.
>
> On Tue, Aug 14, 2018 at 11:39:20PM -0400, Bize Ma wrote:
> > On Tue, 14 Aug 2018 12:34:31, Greg Wooledge said:
> >
> > > I will also repeat, once more, my advice that one should NEVER write
> > > a script containing an unquoted $* or $@ expansion.
> >
> > That is plainly INCORRECT, Greg.
>
> You are incorrect.


I am always incorrect, I like to be so.
But  we are discussing an issue, not my personal problems.


> > > It breaks in all kinds of ways in more than one shell.
> >
> > That several shells do different things is a bug on those shells, not
> bash.
>
> Agreed.


Excellent, we agree.


> And the fact that IN REAL LIFE, THOSE SHELLS EXIST AND HAVE
> THOSE BUGS, which are triggered by incorrect code


No, sorry, but bugs are triggered by perfectly good code, that's why they
are called bugs.


> , is a reason to write
> code correctly so as not to trigger those bugs.
>

Writing code to *work around* bugs is *not* the correct solution.
It is only a way to *perpetuate* those bugs.
The correct solution is to resolve the bugs.

But this is just a smoke curtain. There are no bugs about $@ and $* in Bash.

Or maybe you're one of those people who doesn't care about reality.
>

Sometimes I don't , most of the time when I sleep, sometimes when I day
dream.


> > > Just don't do it, and these problems go away.
> >
> > If I want the split+glob to take effect I can do:
> >
> >    echo $*
> >
> >
> > There is nothing wrong with that (don't claim that it change in different
> > shells, that is a different issue than using split+glob in bash, go back
> to
> > the point above about other shells if you wish).
>
> There is absolutely definitely positively 100% certainly something wrong
> with that.
>

Ah, yes, that's correct, thanks, I should have used printf, not echo.
But you corrected it, thanks again.

Let's break your script, shall we?
>
> Here's your script, except I'm going to represent it as a function.  Doing
> it as a script would have the same effect.
>
> glob() {
>     # "Return" (write to stdout, one per line) the expansions of all
>     # arguments as globs against the current working directory.
>     printf %s\\n $*
> }
>
> Will you at least agree that this is your intent,


No, that is *not* my intent.
You can not implement a glob function when *both: split and glob* are in
effect.

If you want a glob function, stop the split, set IFS to null:

    $ cat script
    #!/bin/bash
    glob() ( IFS=; printf %s\\n $* )
    glob '*Web Service*'

    $ ./script
    Epic Web Service - PatientLookup.pdf


and a fair
> representation of your proposed solution?  I'll take that as a "yes".
>

No it is not a fair representation of anything I said.
Only of a twist that you want to present here.

So now, you can pass SOME globs to it (properly quoted), and it will
> appear to work for those globs:
>

But it will fail to work on the next example as you want to demonstrate,
therefore you have not coded correctly to workaround the shells bugs
(your own words).

Some of us care about reality.
>

Yes, when I am awake.

Other languages have no problem with this.  Tcl,

(...)

But we are in bash, are we not?


Now, you tried to implement Tcl's [glob] in bash, but you did it naively
> and the naive version does not work.  You took a shortcut.  That shortcut
> falls off a cliff.
>

No, *you* did. You implemented a flawed glob function.


> I'll leave the non-broken implementation as an exercise for the reader.
>

You are not able to do it?


> Now, back to the original points:
>
> 1) Certain shells have bugs in them.  These shells are in widespread use
>    on real systems in real life.
>
> 2) One of those shells is bash, which makes it relevant to bug-bash.
>
> 3) Some of those bugs involve the unquoted expansions of $* and $@.
>

Not in bash.


> 4) Even in the ABSENCE of such bugs, the use of an unquoted $* or $@
>    expansion does not actually solve the problems you claim it solves.
>

I claimed nothing. I presented a valid use. Don't put words in my mouth.


> 5) Therefore, for TWO reasons, you should not use unquoted $* or $@
>    in your shell scripts.
>
>    Reason 1: it doesn't solve the problem.
>    Reason 2: it sometimes breaks even worse due to shell bugs.
>

There is no therefore if the premises are wrong.

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: Assignment of $* to a var removes spaces on unset IFS. Bize Ma <binaryzebra@gmail.com> - 2018-08-15 11:54 -0400

csiph-web