[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Spaces in File name Handling
From: |
Paul Jarc |
Subject: |
Re: Spaces in File name Handling |
Date: |
Sat, 13 Mar 2004 02:55:22 -0500 |
User-agent: |
Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (gnu/linux) |
alupu@att.net wrote:
> I thought I'd seen Unix before but I'm still reeling after finally
> realizing that the output of the good old "list", ls, has - behind
> the scenes - the file names separated by LF and not by spaces as it
> appears on the screen of the unsuspecting (and uninitiated) user.
The output is separated by spaces, just as it appears, when ls is
writing to a tty. But if it notices that it is writing to a pipe, as
is the case for `command substitution`, then it writes just one name
per line. You can also force this behavior with "ls -1".
> # In a directory with three files, "A", "B C" and this "T" procedure:
> TMP=`ls -A`
> echo $TMP > E
At this point, $IFS still has the default value - space, tab, and
newline - so echo sees four arguments ("A", "B", "C", "T").
> When the shell hands over an argument ($TMP) to "echo" it removes
> the LFs while in the "for" construct it doesn't touch them.
No, it does. Unquoted variable expansions get split at $IFS
delimiters in either case. (If it weren't split for "for", then you'd
get all of $TMP in one instance of $i, just like when $TMP is quoted.)
In the "for" case, we set IFS so that $TMP will be split *only* at
newlines.
paul