help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Pathname expansion without word splitting


From: Sebastian Unger
Subject: Re: [Help-bash] Pathname expansion without word splitting
Date: Thu, 17 Sep 2015 20:35:38 +1200

Brilliant. I'm not entirely sure why I didn't arrive at that myself. I did
even think about setting IFS to null like so:
IFS= eval 'array=("address@hidden")'
Obviously with the double quotes the pathname expansion doesn't happen, but
I must have trained myself so hard over the years to ALWAYS double-quote
variable expansions, that I couldn't even conceive of a solution without
them anymore.

I think this is the first time in about 20 years bash scripting that I have
found a legitimate (and required) use of unquoted variable expansion.

Thanks!
Seb
On 17 Sep 2015 7:58 pm, "Geir Hauge" <address@hidden> wrote:

> On Thu, Sep 17, 2015 at 12:41:45PM +1200, Sebastian Unger wrote:
> > Hi There,
> >
> > I have tried to work this out by myself, but despite many years
> experience
> > writing bash scripts I was stumped a bit by this one:
> >
> > Given an array of pathname patterns, create a new array with all matching
> > file names (and only those) without running an external command. Be aware
> > that the pathname patterns may contain blanks (otherwise it would be too
> > simple ;-).
>
> You disable word splitting by assigning the empty string to IFS
>
>     shopt -s nullglob
>     IFS=
>     array=( address@hidden )
>
> --
> Geir Hauge
>

-- 

------------------------------
This email, including any attachments, is only for the intended recipient. 
It is subject to copyright, is confidential and may be the subject of legal 
or other privilege, none of which is waived or lost by reason of this 
transmission.
If you are not an intended recipient, you may not use, disseminate, 
distribute or reproduce such email, any attachments, or any part thereof. 
If you have received a message in error, please notify the sender 
immediately and erase all copies of the message and any attachments.
Unfortunately, we cannot warrant that the email has not been altered or 
corrupted during transmission nor can we guarantee that any email or any 
attachments are free from computer viruses or other conditions which may 
damage or interfere with recipient data, hardware or software. The 
recipient relies upon its own procedures and assumes all risk of use and of 
opening any attachments.
------------------------------


reply via email to

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