comp.lang.ada
 help / color / mirror / Atom feed
From: Keith Thompson <kst-u@mib.org>
Subject: Re: Interpretation of extensions different from Unix/Linux?
Date: Wed, 19 Aug 2009 13:39:19 -0700
Date: 2009-08-19T13:39:19-07:00	[thread overview]
Message-ID: <lnmy5vv8qw.fsf@nuthaus.mib.org> (raw)
In-Reply-To: h62s7i$2ta$1@munin.nbi.dk

"Randy Brukardt" <randy@rrsoftware.com> writes:
> "vlc" <just.another.spam.account@googlemail.com> wrote in message 
> news:8a5f3b98-1c5a-4d47-aca7-e106d1223fa9@a26g2000yqn.googlegroups.com...
> ...
>>If the specifications are different, the utilities in Ada.Directories
>>are quite unusable for UNIX/Linux.
>
> I think you are seriously confused about how this stuff works in Unix. 
> (Either that, or I'm getting senile... ;-)
>
>> In case I want to process all *.c files in a given directory, I could code 
>> something like
>>
>>with Ada.Directories; use Ada.Directories;
>>
>>procedure Parse is
>>   procedure Do_It (Directory_Entry : Directory_Entry_Type) is
>>   begin
>>      -- Do something
>>   end Do_It;
>>begin
>>   Ada.Directories.Search (".", "*.c", (others => True), Do_It'Access);
>>end Parse;
>>
>>If I want to ensure me what files will be processed, I would call e.g.
>>
>>ls -A *.c
>>
>>first. But if there would be a file ".c" in the current directory, it
>>would not be listed by the "ls" command, but processed by my program.
>
> But "ls" does not display all of the files by default! You need an option (I 
> don't recall which one; I used to always use "ls -al" but I no longer 
> remember why) to see the files that start with a ".". That doesn't mean that 
> they don't match the wildcard, it just means that "ls" doesn't display them.
>
> If you did an "ls *.", that wouldn't display ".", either, but there still is 
> a file with that name in the directory.

A lot of this has already been covered, but I'll summarize.

The ls command, like most Unix commands, doesn't handle wildcards.
Wildcards are expanded by the shell before ls is invoked.  If the
current directory contains just foo.c and bar.c, then the ls command
can't tell the difference between "ls *.c" and "ls bar.c foo.c"; it
receives exactly the same arguments in both cases.

Wildcard expansion does not include files whose names start with '.',
unless the pattern actually starts with a '.' character.  Different
shells may differ in how they handle wildcards, but on this particular
point I think all the common shells consistent.

The ls command, if invoked with no arguments or with a directory
argument, lists the files in current or specified directory, excluding
files whose names start with '.'.  The "-a" option to ls overrides
this, and tells it to list all files including dot files.  The "-A"
option (which may not exist in all versions of ls) includes dot files
but excludes "." and "..".

So the exclusion of files whose names start with '.' is done in two
different places: by wildcard expansion (handled by the shell) and in
a directory listing without the "-a" or "-A" option (handled by the ls
command).

Suppose the current directory contains "foo.c", "bar.c", and ".c".

% ls
bar.c  foo.c
% ls -a
.  ..  .c  bar.c  foo.c
% ls *.c
bar.c  foo.c
% ls -a *.c
bar.c  foo.c

"ls -a" causes the ls command to read the directory and list all
files, including those whose names start with '.'.

In "ls -a *.c", the *.c wildcard is expanded by the shell, so the ls
command sees the arguments "-a bar.c foo.c".  It doesn't list ".c"
because it wasn't asked to do so.

> Ada.Directories.Search does "display" all filenames, of course, as there is 
> no filter to match the goofy behavior of "ls". So you see this file that 
> "ls" does not show.
>
> My recollection (mostly from the CSH on Unix, SCO, and Sun OS, which 
> admittedly is a long time ago) is that this is a feature of "ls" only. That 
> is, if you write your own program "wobble" and then call it
>
>     wobble *.c
>
> you would in fact get the file ".c" in the list of files passed. After all, 
> "*.c" is just a regular expression, and one that clearly matches the string 
> ".c" (since '*' means match 0 or more arbitrary characters).

No, "wobble *.c" will not cause the wobble command to see ".c".
Neither ls nor wobble does anything special with wildcards; neither is
a built-in command.

[...]

Note that if you invoke the ls command other than from a shell, for
example in Perl:

    system('ls', '*.c');

then no wildcard expansion is done, and the ls command receives the
string "*.c" as an argument.  This will result in an error message,
unless there happens to be a file in the current directory whose name
is "*.c" (which is perfectly legal, but can cause problems).  You can
achieve the same effect from the shell by quoting the argument:

    % ls '*.c'

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"



  parent reply	other threads:[~2009-08-19 20:39 UTC|newest]

Thread overview: 104+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-01 17:53 Interpretation of extensions different from Unix/Linux? vlc
2009-08-02 17:13 ` Jacob Sparre Andersen
2009-08-04 11:31   ` vlc
2009-08-04 11:44     ` Jacob Sparre Andersen
2009-08-04 11:57       ` Georg Bauhaus
2009-08-04 12:29         ` vlc
2009-08-04 13:43         ` Dmitry A. Kazakov
2009-08-14  4:33           ` Randy Brukardt
2009-08-14  7:37             ` Dmitry A. Kazakov
2009-08-04 12:25       ` vlc
2009-08-04 19:18         ` Jeffrey R. Carter
2009-08-04 19:52           ` Dmitry A. Kazakov
2009-08-04 20:45             ` Jeffrey R. Carter
2009-08-04 21:22               ` Dmitry A. Kazakov
2009-08-04 22:04                 ` Jeffrey R. Carter
2009-08-05  8:33                   ` Dmitry A. Kazakov
2009-08-05 16:07                     ` Jeffrey R. Carter
2009-08-05 16:35                       ` Dmitry A. Kazakov
2009-08-05 17:49                         ` Jeffrey R. Carter
2009-08-05 18:16                           ` Dmitry A. Kazakov
2009-08-05 19:27                             ` Jeffrey R. Carter
2009-08-05 19:50                               ` Dmitry A. Kazakov
2009-08-05 20:46                                 ` Jeffrey R. Carter
2009-08-06  7:43                                   ` Dmitry A. Kazakov
2009-08-05 21:33                               ` Robert A Duff
2009-08-05 19:45                           ` vlc
2009-08-05 19:56                             ` Dmitry A. Kazakov
2009-08-14  4:56                     ` Randy Brukardt
2009-08-14  8:01                       ` Dmitry A. Kazakov
2009-08-14 23:02                         ` Adam Beneschan
2009-08-14 23:54                         ` Randy Brukardt
2009-08-15  8:10                           ` Dmitry A. Kazakov
2009-08-15 12:49                             ` Pascal Obry
2009-08-15 13:23                               ` Dmitry A. Kazakov
2009-08-15 15:11                                 ` Pascal Obry
2009-08-15 17:11                                   ` Dmitry A. Kazakov
2009-08-15 20:07                                     ` Pascal Obry
2009-08-16  7:26                                       ` Dmitry A. Kazakov
2009-08-17 22:28                             ` Randy Brukardt
2009-08-18  0:32                               ` Adam Beneschan
2009-08-18 20:48                                 ` Randy Brukardt
2009-08-19  4:08                                   ` stefan-lucks
2009-08-19 22:01                                     ` Randy Brukardt
2009-08-19  7:37                                   ` Jean-Pierre Rosen
2009-08-19 16:10                                   ` Adam Beneschan
2009-08-19 22:11                                     ` Randy Brukardt
2009-08-18  7:48                               ` Dmitry A. Kazakov
2009-08-18 20:37                                 ` Randy Brukardt
2009-08-19  8:04                                   ` Dmitry A. Kazakov
2009-08-19 10:32                                     ` Georg Bauhaus
2009-08-19 12:11                                       ` Dmitry A. Kazakov
2009-08-19 15:21                                         ` Georg Bauhaus
2009-08-19 22:40                                     ` Randy Brukardt
2009-08-20  8:00                                       ` Variable- and fixed-length-character strings (Was: Interpretation of extensions different from Unix/Linux?) Jacob Sparre Andersen
2009-08-20 19:40                                       ` Interpretation of extensions different from Unix/Linux? Dmitry A. Kazakov
2009-08-21  0:08                                         ` Randy Brukardt
2009-08-21  7:43                                           ` Dmitry A. Kazakov
2009-08-21 22:10                                             ` Randy Brukardt
2009-08-22  7:27                                               ` Dmitry A. Kazakov
2009-09-01  1:50                                                 ` Randy Brukardt
2009-09-01  7:28                                                   ` Dmitry A. Kazakov
2009-09-02  3:41                                                     ` Stephen Leake
2009-09-02  7:17                                                       ` Dmitry A. Kazakov
2009-09-02 19:49                                                         ` tmoran
2009-09-03  7:41                                                           ` Dmitry A. Kazakov
2009-09-03 17:27                                                             ` tmoran
2009-09-03 20:44                                                               ` Dmitry A. Kazakov
2009-09-03 22:22                                                                 ` Randy Brukardt
2009-09-04  7:40                                                                   ` Dmitry A. Kazakov
2009-09-05  1:58                                                                     ` Randy Brukardt
2009-09-05  2:08                                                                     ` Randy Brukardt
2009-09-05  8:59                                                                       ` Dmitry A. Kazakov
2009-08-21 10:11                                           ` Enumeration of network shared under Windows (was: Interpretation of extensions different from Unix/Linux?) Dmitry A. Kazakov
2009-08-15 16:01                           ` Interpretation of extensions different from Unix/Linux? Vadim Godunko
2009-08-16 13:13                           ` Stephen Leake
2009-08-14  4:46                 ` Randy Brukardt
2009-08-14  9:00                   ` Dmitry A. Kazakov
2009-08-04 21:19           ` vlc
2009-08-14  5:19     ` Randy Brukardt
2009-08-14  6:13       ` Wilcards in Linux (was: Interpretation of extensions different from Unix/Linux?) stefan-lucks
2009-08-14  6:24         ` stefan-lucks
2009-08-14 10:05         ` Wilcards in Linux Markus Schoepflin
2009-08-14 10:22           ` Ludovic Brenta
2009-08-14 18:20             ` Tero Koskinen
2009-08-19 20:39       ` Keith Thompson [this message]
2009-08-19 22:09         ` Interpretation of extensions different from Unix/Linux? Robert A Duff
2009-08-20  7:49           ` Jacob Sparre Andersen
2009-08-20 15:56             ` Adam Beneschan
2009-08-20 21:58               ` sjw
2009-08-20 19:44             ` Robert A Duff
2009-08-20 21:34               ` Adam Beneschan
2009-08-20 22:03                 ` (see below)
2009-08-21  0:55                 ` tmoran
2009-08-20 23:55               ` Randy Brukardt
2009-08-21 17:58               ` Keith Thompson
2009-08-21 18:34                 ` Dmitry A. Kazakov
2009-08-21 19:32                 ` Jeffrey R. Carter
2009-08-21 21:34                 ` Robert A Duff
2009-08-21 22:06                   ` Hyman Rosen
2009-08-24 19:51                   ` Keith Thompson
2009-08-28  0:27                     ` Robert A Duff
2009-08-28 13:15                       ` Anders Wirzenius
2009-08-28 15:02                         ` Robert A Duff
2009-08-21  8:45             ` Stephen Leake
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox