Path: csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: Ilkka Virta Newsgroups: gnu.bash.bug Subject: Re: Assignment of $* to a var removes spaces on unset IFS. Date: Wed, 15 Aug 2018 16:08:03 +0300 Lines: 34 Approved: bug-bash@gnu.org Message-ID: References: <20180815124455.ta5t6orhy3csgh4y@eeg.ccf.org> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1534338498 9970 208.118.235.17 (15 Aug 2018 13:08:18 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash@gnu.org To: Greg Wooledge Envelope-to: bug-bash@gnu.org User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 In-Reply-To: <20180815124455.ta5t6orhy3csgh4y@eeg.ccf.org> Content-Language: en-US X-SASI-RCODE: 200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; h=subject:to:references:from:cc:message-id:date:mime-version:in-reply-to:content-type:content-transfer-encoding; s=smtp; bh=+ICOD15VCRtTTHG+kcK2/2C1obs4NKvrN3YNCnAPfF8=; b=gBWAJi8xKkphvoRSEXbR6dmEyBUkAyy5rZx2JT05swDYF9cz6SgKVX67rIb/M8UwySXd7xbwm8bBMxOOTatNQNz9snra1+k7A5WG7/9zixn/4+K/0t2ixV0ePbzQ81gRSKegcvJ2WYJec0XFV5gSatRhP90nSBtB9rX3PKKZGtu8rB63YAkISh1yqNCQBkktKK5Puo8rBlKtCa3QhIPOHoovjYebp6LUUb1mpJdNub5mFLKL5bOmbjgMuPWidY7YMllapaRht7M/25G5OBtj/Qno70igS/V22TMAsTOpn+eBmgLZcuwEHLorl3hO/Ahq/dNKjKJEU2ybq/lRDkLNVQ== X-detected-operating-system: by eggs.gnu.org: FreeBSD 8.x X-Received-From: 157.24.2.213 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:14494 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