Thanks for your report.  It is much appreciated.  However what you are
seeing is normal behavior.

Juergen Katins wrote:
> Beeing in /etc I type "ls foo*".
> I am expecting too get all files/directories whose name begins with "foo". 
> What I get is this:
> [EMAIL PROTECTED]:/etc$ ls foo*
> defaultspooler  direct  filter.conf
> None of this three files/directories begins with "foo".
> 
> The program "ls" actually lists all files/directories, being in the directory 
> "foomatic". 

Yes.  The shell is expanding the '*' wildcard on the command line.
The result is that ls is being told to list the foomatic directory.

> Suggested solution: 
> 
> When ls finds more then one matching file/directory it lists the name of the 
> found 
> directory too. 
> ls should do this also when it finds only one matching directory. 

The '*' wildcard expansion (called file globbing, because the '*'
matches a glob of characters) is being expanded by the shell.  The
result is then being handed to the ls program.  The ls program never
sees the '*' wildcard and has no way of knowing about it.  The ls
program has no way to tell that you expanded a "glob" to match either
a single file or more than one file.

> The output should look like this: 
> 
> [EMAIL PROTECTED]:/etc$ ls foo*
> foomatic:
> defaultspooler  direct  filter.conf

Check the command with 'echo'.  Use 'echo' to perform the file
globbing and look at the result.

  echo ls foo*
  ls foomatic

  echo ls foomatic
  ls foomatic

What you will see is "ls foomatic".  There is no way to distinguish
this from having typed in a literal "ls foomatic".  The ls program can
only act as if it had been asked to list the foomatic directory.

You will find benefit from the 'ls -d' option.  It prevents ls from
listing the contents of directories.  In the case that you are
presenting here you would say 'ls -d foo*' and see the literal
foomatic result.

  ls -d foo*
  foomatic

You may wonder why the shell does the file glob expansion and not the
program.  The separation of file glob expansion from the command line
utilities is a fundamental design feature of GNU/UNIX systems.  If
every program included file glob expansion themselves then it would be
difficult to have them all do it the same way.  Some would be one way
and some would be another way.  We know this because other systems are
like this.  By having the shell do the processing, all of the programs
use the same command line processing.  They are all uniformly handled.
This brings consistency to the system.  And also this was a feature of
the earliest systems 30 years ago.  So at this late time there is a
large legacy base of applications that depend upon the current
behavior.

Hope this helps,
Bob

-- 
Bob Proulx <[EMAIL PROTECTED]>
http://www.proulx.com/~bob/


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to