Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #14494 > unrolled thread
| Started by | Ilkka Virta <itvirta@iki.fi> |
|---|---|
| First post | 2018-08-15 16:08 +0300 |
| Last post | 2018-08-15 16:08 +0300 |
| Articles | 1 — 1 participant |
Back to article view | Back to gnu.bash.bug
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Assignment of $* to a var removes spaces on unset IFS. Ilkka Virta <itvirta@iki.fi> - 2018-08-15 16:08 +0300
| From | Ilkka Virta <itvirta@iki.fi> |
|---|---|
| Date | 2018-08-15 16:08 +0300 |
| Subject | Re: Assignment of $* to a var removes spaces on unset IFS. |
| Message-ID | <mailman.5136.1534338498.1292.bug-bash@gnu.org> |
On 15.8. 15:44, Greg Wooledge wrote:
> glob() {
> # "Return" (write to stdout, one per line) the expansions of all
> # arguments as globs against the current working directory.
> printf %s\\n $*
> }
>
> But... but... but... the PREVIOUS glob worked! Why didn't this one
> work?
I'm sure you know what word splitting is.
> I'll leave the non-broken implementation as an exercise for the reader.
$ glob() { local IFS=; printf '%s\n' $*; }
$ touch "foo bar.txt" "foo bar.pdf"
$ glob "foo bar*"
foo bar.pdf
foo bar.txt
(Well, you'd probably want 'nullglob' too, and there's the minor issue
that printf '%s\n' prints at least one line even if there are no
arguments but I'll ignore that for now.)
Of course, in most cases, and unquoted expansion is not what one wants,
but if there's need to glob in the shell, then an unquoted expansion is
what has to be used. How IFS affects word splitting isn't just about
$* , the issue is the same even if you only have one glob in a regular
variable.
--
Ilkka Virta / itvirta@iki.fi
Back to top | Article view | gnu.bash.bug
csiph-web