bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Ilkka Virta
Subject: Re: Assignment of $* to a var removes spaces on unset IFS.
Date: Wed, 15 Aug 2018 16:08:03 +0300
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.9.1

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 / address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]