[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Spaces in File name Handling
From: |
alupu |
Subject: |
Re: Spaces in File name Handling |
Date: |
Sat, 13 Mar 2004 22:31:53 +0000 |
Hi Paul,
Thank you very much for your comments and clarifications.
Again, at your leisure, your words on the following will be highly appreciated.
> Alex says (excerpts):
When the shell hands over an argument ($TMP) to echo it removes the LFs ...
...
Does this go all the way back to the old Doug McIlroy philosophy on echo
described in The Unix Programming Environment - Using the Shell, by BWK and
RP?
>> Paul replies (excerpts):
... but if [ls] notices that it is writing to a pipe, as is the case for
`command substitution`, then it writes just one name per line.
...
> # 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").
...
Unquoted variable expansions get split at $IFS delimiters in either case.
-- Alex (live):
Not really, "echo $TMP" appears to have the LFs stripped (staying with the
original example - with $IFS at default, before being subsequently modified to
accept only LFs).
# Same old directory, three files, A, B C and this T procedure:
TMP=`ls -A`
echo $TMP > E
echo "$TMP" > F
cat E:
A B C T
cat F (surprise, surprise):
A
B C
T
Not surprisingly now, for completeness, dump E:
41 20 42 20 43 20 54 0a
and dump F:
41 0a 42 20 43 0a 54 0a
It appears that if I _quote_ the argument to echo, the shell will finally
behave as expected (by the uninitiated) and echo will show the naked truth
(splits and all). Had I known that (or seen it mentioned somewhere) I _may_
have had the chance to figure out the $IFS business on my own and avoid a lot
of sleepless nights and weight loss and, what's more important, save you the
aggravation of dealing with me!
Oh well, when all your life you're told to 'echo $PATH' (and not 'echo
"$PATH"') you miss the bigger picture at times.
So I'm taking the liberty of again asking for your thoughts on the preceding
e-mail's last question (Doug's whimsical take on "echo and LF" - full text at
the beginning of this letter).
Many thanks and best wishes,
-- Alex