Re: [vox-tech] shell question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [vox-tech] shell question
- Subject: Re: [vox-tech] shell question
- From: Micah Cowan <micahMAPS@cowanbox.com>
- Date: Thu, 02 Nov 2000 11:09:19 -0800
- References: Pine.LNX.4.21.0011020901150.12263-100000@belial.ucdavis.edu
On Thu, Nov 02, 2000 at 09:09:56AM -0800, Peter Jay Salzman wrote:
> consider the following directory:
>
> % ls
> A 1st file A 3rd file A 5th file A 7th file
> A 2nd file A 4th file A 6th file
>
> i don't understand what's going on here; spaces in the filename seem to
> delineate the end of the file, according to the following script. i trust
> echo. the problem must be `ls`.
>
> % for i in `ls`; do echo $i; done
> A
> 1st
> file
> A
> 2nd
> file
> A
> 3rd
> ... (etc)
>
>
I can explain why. The backticks gets the literal output of ls, which is
then used as a list in for. Once the output is received, bash has no way
of knowing which spaces are part of the filename - all it knows is it has
a bunch of words seperated by spaces. This is not a bug in echo, ls, or
bash - it's just slightly incorrect usage.
What *will* work is:
$ for i in *; do echo $; done.
Because this returns a bash glob-spawned list, which will produce the literal
filenames, and it will work correctly because bash isn't forced to seperate
tokens - it gets them already seperated.
Hope that helps!
BTW, using '%' for the prompt is usually a csh thing - as you seem
to be talking about bash flow control structures, etc., you should
probably use '$'.
Micah
|