bug-bash
[Top][All Lists]
Advanced

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

Re: Spaces in args, escapes, and command substitution


From: Chet Ramey
Subject: Re: Spaces in args, escapes, and command substitution
Date: Sun, 29 Oct 2006 14:54:36 -0500
User-agent: Thunderbird 1.5.0.7 (Macintosh/20060909)

bash@zacglen.com wrote:
>> Word splitting is controlled by IFS.  Use IFS=$'\n' to only split on
>> newlines.
>>
>> Andreas.
> 
> Well, I still dont see any examples.  I don't think it is possible even
> using IFS.  Even if it does work somehow, it isn't easy or intuitive.

Oh, for pete's sake.  Take a systematic approach, as Andreas suggested.
First, arrange for the filenames you want to be delimited by newlines.
Since this is for your own use, and you can more-or-less guarantee that
there will never be a newline in a filename, that's sufficient.  Second,
arrange things so that the shell won't split words on anything but
newline, your desired delimiter.

Take a look at the approach in the following example script.  `recho' is
part of the bash distribution; it's built while running the test suite.
I used `ls -1' to create a newline-delimited list of filenames.

$ cat x3
[ -d scratch ] || mkdir scratch
cd scratch
touch 'a b  w' 'c d  x' 'e f  y' 'g h  z'

IFS=$'\n'
recho $(ls -1 *)
$ ../bash-3.2/bash ./x3
argv[1] = <a b  w>
argv[2] = <c d  x>
argv[3] = <e f  y>
argv[4] = <g h  z>

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                       Live Strong.  No day but today.
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/




reply via email to

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