rich@eddie.MIT.EDU (Richard Caloggero) (08/06/88)
What am I doing wrong? I think the following script should print 'yes' three times. ----- #!/bin/csh set x=stuff_and_more echo try one: if "$x" =~ "stuff*" echo yes echo try two: alias x 'if "$x" =~ "stuff*" echo yes' x echo try three: alias x 'if "$x" =~ "stuff"* echo yes' x ---------- It only prints 'yes' once -- on try three. I'm sure it has something to do with my poor understanding of csh's various quoting conventions. -- -- Rich (rich@eddie.mit.edu). The circle is open, but unbroken. Merry meet, merry part, and merry meet again.
greim@sbsvax.UUCP (Michael Greim) (08/08/88)
In article <9832@eddie.MIT.EDU>, rich@eddie.MIT.EDU (Richard Caloggero) writes: < < < What am I doing wrong? < I think the following script should print < 'yes' three times. < < ----- < #!/bin/csh < set x=stuff_and_more < echo try one: < if "$x" =~ "stuff*" echo yes < < echo try two: < alias x 'if "$x" =~ "stuff*" echo yes' < x < < echo try three: < alias x 'if "$x" =~ "stuff"* echo yes' < x < < ---------- < < < It only prints 'yes' once -- on try three. < I'm sure it has something to do with my < poor understanding of csh's various quoting conventions. < It's a bug in csh or at least an undocumented strangeness. There has been some discussion some months ago about how to fix it, or indeed if we should fix it at all. Rob McMahon (hello!) and me have had a lot of arguments on how to fix it, and we have come up with a solution, well, sort of. I wanted to write a short text on pattern matching, but as I am rather lazy normally, this has rested in my shelves until now. I promise I will look into it again. If you have source code, you are lucky, if not, you will have to contact someone who has for the modified version. (the following may lack in accuracy due to some memory fault of the author's) 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. A fix I made some months ago and posted to the net took care of this bug, I think. It was listed as <486@sbsvax.UUCP> from 25.apr.88. But there were still some flaws in pattern matching which it might even be impossible to straighten out. BTW: Did you ever wonder why 'if "$x" =~ "stuff"*' does not try to do any filename substitution? The big question is : should it ? -mg -- +------------------------------------------------------------------------------+ | UUCP: ...!uunet!unido!sbsvax!greim | Michael T. Greim | | or greim@sbsvax.UUCP | Universitaet des Saarlandes | | CSNET: greim%sbsvax.uucp@Germany.CSnet| FB 10 - Informatik (Dept. of CS) | | ARPA: greim%sbsvax.uucp@uunet.UU.NET | Bau 36, Im Stadtwald 15 | | Phone: +49 681 302 2434 | D-6600 Saarbruecken 11, West Germany | +------------------------------------------------------------------------------+ | # include <disclaimers/std.h> | +------------------------------------------------------------------------------+