ls

Mark Bush bush%ecs.oxford.ac.uk at nsfnet-relay.ac.uk
Wed Oct 11 04:37:34 AEST 1989


>>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 at ac.uk
Teaching Support Programmer    bush%prg.oxford.ac.uk at nsfnet-relay.ac.uk
OUCL                           ...!uunet!mcvax!ukc!ox-prg!bush



More information about the Comp.unix.wizards mailing list