I'm trying to use the =~ operator in my .cshrc so that I can check
whether I'm running SunOS 4.1.3 or Solaris 5.x. `uname` on both
systems returns "SunOS" while `uname -r` returns strings like
"4.1.3_U1" or "5.2".
I would prefer to use the csh =~ operator instead of a more verbose
switch statement.
if (`uname -r` =~ "4*") then
set path = (~/local/sunos.bin $path)
else
set path = (~/local/solaris.bin $path)
endif
Unfortunately the test always fails. Why doesn't "4*" match
"4.1.3"? The csh man page says:
== != =~ !~ equal to, not equal to, filename-
substitution pattern match
(described below), filename-
substitution pattern mismatch
[...]
The operators: ==, !=, =~, and !~ compare their arguments as
strings; other operators use numbers. The operators =~ and
!~ each check whether or not a string to the left matches a
filename substitution pattern on the right. This reduces
the need for switch statements when pattern-matching between
strings is all that is required.
Thanks,
Jamshid Afshar