the gnu utility expr fails in the follow 2 cases: expr length "(" and expr length ")" escaping the ( and ) as '(' ')' or \( \) has no effect expr reports these 2 cases as: expr: syntax error readily reproducible from command line all other single character strings containing all letters of alphabet in both cases and all other special characters on standard US keyboard are evaluated correctly by expr returning correctly a length of 1. The addition of another character with either ( or ) correctly returns a length of 2 so it does not appear to be a case of expr requiring balanced parentheses. Problem first detected on RH6.0 with sh-utils-1.16.23 while using expr in a bash script. I then upgraded sh-utils-2.0-1 from a rh6.1 distribution on my rh6.0 machine (upgrade successful, no warning or errors). exactly the same results. here is a test script I wrote to check special characters. for l in "~" "!" "@" "#" '$' "%" "^" "&" '*' "(" ")" "_" "+" "\`" "-" "=" "\\" "|" "," "." "/" "<" ">" "?" "{" "}" "[" "]" do echo -n "$l " expr length "$l" done For what it is worth HP-UX 10.20 expr exhibits the same behavior. paul almquist, instructor & sys admin almquipf.tec.wi.us
According to the base maintainer, this is the expected behavior (and compatible with pretty much all other unixes).