what is the correct way to code this perl statment in tcsh shell script
foreach (@array) { if 开发者_运维问答(/^(pam|pom)/) { dosomething(); } }
Here's one way:
#!/bin/tcsh -f
set array = ( foo pam bar pom baz xpam pamx )
alias dosomething echo
foreach elem ($array:q)
if ($elem:q =~ {pam,pom}*) then
dosomething $elem:q
endif
end
Note that the expression on the right side of the =~
operator is a file matching pattern, not a regular expression, so this solution doesn't generalize to all cases. If you need regular expression matching, you can use the expr
command:
expr STRING : REGEXP
or, equivalently:
expr match STRING REGEXP
精彩评论