CSH Help -- I don't get it ...

Damian Cugley pdc at otter.hple.hp.com
Thu Aug 11 02:03:30 AEST 1988


/ comp.unix.questions / greim at sbsvax.UUCP (Michael Greim) /  Aug  8, 1988 /

> < if "$x" =~ "stuff*" echo yes
> < alias x 'if "$x" =~ "stuff*" echo yes'
> < x
> < alias x 'if "$x" =~ "stuff"* echo yes'
> < x
> <     It only prints 'yes' once -- on try three.
> It's a bug in csh or at least an undocumented strangeness.

It may not be a bug. It *is* consistent with the rest of csh.

"..."  quoting prevents pattern patching when expanding filenames in
commands, so it makes sense for the same to happen when using patterns
with =~ or !~.  

In the first two of his 'if' examples, the * was quoted, i.e.  it was no
longer 'magical'.  In the last one the * is magic and so pattern
matching works.  The quotes around the $x and the use of 'alias' are all
red herrings.

> In your first example the string resulting from expanding "$x" has
> no 8 bit turned on, but the string "stuff*" has. Thus "*" is not recognized
> as a shell meta character.

I don't think this makes much sense to me - I wonder what the person
asking the question made of it :-( .  The * isn't recognised as being
magical because it is quoted (i.e.  in "...").  Exactly how csh keeps
track of what's quoted and what isn't is beside the point.

>                             A fix I made some months ago and posted to the
> net took care of this bug, I think. It was listed as <486 at sbsvax.UUCP>
> from 25.apr.88. But there were still some flaws in pattern matching
> which it might even be impossible to straighten out.

I don't *think* it's a bug (I don't claim to be an expert).  In the man
page for csh it says "..."  prevents filename expansion, i.e. makes *
unmagical.  It should've said it made it unmagic in =~ patterns too, but
that's a reasonable deduction.  

Why would it be useful for pattern-matching to work even when quoted?
How then would we turn it *off*!?  If there's no bug, 'fixing' it will
only cause more problems (i.e. introduce more bugs...).

> BTW:
> Did you ever wonder why 'if "$x" =~ "stuff"*' does not try to do
> any filename substitution? The big question is : should it ?

No, I didn't wonder.  No, it shouldn't.  'If's are special csh keywords,
and the test part isn't a command; hence there's no reason whatsoever
why it should try to expand patterns into filenames in the test part of
an 'if'.

--
Damian Cugley			'His feet are the wrong size for his shoes.'



More information about the Comp.unix.questions mailing list