[comp.unix.wizards] ls

bush%ecs.oxford.ac.uk@nsfnet-relay.ac.uk (Mark Bush) (10/11/89)

>>What about
>>when I do want to grep all of the files (but not . and ..) in the
>>current directory?  Shell globbing alone is not sufficient for this
>>where .files exist.
>
>grep 'pattern' .??* *
 
What about `.a'?  The pattern `.??*' will not pick out this file.  Using
`.?*' will get `..'.  If you use csh then you would need to make some sort
of script that did something like:

#!/bin/csh -f

foreach i ("`ls -A`")
    set found="`grep $1 $i`"
    if ($found != "") then
        echo "<<< $i >>>"
        echo $found
    endif
end

where the first argument is the pattern to search for.  A bit ugly yeah?
Even if you have a shell that can do *real* globbing then:

grep 'pattern' .[^.]* *

will probably match `.'!

If you know that filenames are going to have alphanumeric characters after
any leading `.' then:

grep 'pattern' .[a-z0-9]* *

would work, but a bit restrictive.  Unfortunately, the character before `.'
is `-' and I haven't been able to get:

.[\ -\\\-\/-~]*

to work using any number of `\'s to match a `-'! (bash 1.03)  The pattern:

.[\ -,\/-~]*

does work in bash but seems to want to include both `.' and `..' in csh!!!!
Of course this pattern precludes files starting `.-' as well but who cares?

The inconsistancies here are more far reaching that it seems at first.
Perhaps shells should be written so that `.*' precludes `.' and `..'?  After
all, how many times have you wanted to do exactly this sort of thing and
*not* include `.' and `..'.  Is it too much to say:

. .. .* *

when you really want everything?  Am I now going to get flamed at for
introducing yet *another* way of making `.' and `..' special?  After all,
`.' files are special already (except for root---I agree that this `ls -A'
thing is absurd), so why not have `.' and `..' extra special?

(Hasty retreat out of firing range)

Mark Bush                      bush%uk.ac.oxford.prg@ac.uk
Teaching Support Programmer    bush%prg.oxford.ac.uk@nsfnet-relay.ac.uk
OUCL                           ...!uunet!mcvax!ukc!ox-prg!bush

news@bbn.COM (News system owner ID) (10/14/89)

In article <21100@adm.BRL.MIL> bush%ecs.oxford.ac.uk@nsfnet-relay.ac.uk (Mark Bush) writes:
< grep 'pattern' .[^.]* *
< 
< will probably match `.'!

If the shell is _correctly_ handling the [^LETTERS] regexp (which Sys
V shell thinks is [!LETTERS], but grep knows the truth), then
neither . nor .. will be matched.  Remeber: [ABC] means match one of
'A', 'B', or 'C'.  This is _non-optional_; there must be a letter there.

< .[\ -,\/-~]*
< 
< does work in bash but seems to want to include both `.' and `..' in csh!!!!
< Of course this pattern precludes files starting `.-' as well but who cares?

Neat; a bug.  Tcsh gets this wrong too, in case anyone is wondering;
I'll have to fix that.  It _should_ work in everything.  I think it's
caused by a quoting-bit (8th bit inside csh -- don't ask) problem,
with the \/ (backquoted forward-quote).

Try this:

	capella quant_test 332 -> echo 'foo is bar' > '.-'
	capella quant_test 333 -> echo .[\ --/-~]*
	.-
	capella quant_test 334 -> 

Note that you don't have to quote the second -; it's only magic when
_between_ letters.

< The inconsistancies here are more far reaching that it seems at first.
< Perhaps shells should be written so that `.*' precludes `.' and `..'?

Nope; not at all.  Ever.  If the user can't get the regexp right,
that's not the fault of the shell, and the shell shouldn't be made to
work _wrong_.

		-- Paul Placeway <now PPlaceway@bbn.com>