l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
July 21: Defensive computing: Information security for individuals
Next Installfest:
TBD
Latest News:
Jul. 4: July, August and September: Security, Photography and Programming for Kids
Page last updated:
2001 Dec 30 16:58

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
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


LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.