Subject: Arithmetic, octal and leading zeroes in sh
To: None <netbsd-users@netbsd.org>
From: Stephen Borrill <netbsd@precedence.co.uk>
List: netbsd-users
Date: 10/13/2005 10:38:59
sh (at least between 2.0.2 and 3.0 - 1.6.1 is OK) doesn't seem to like
leading zeros on 8 and 9, but is OK with all other numbers:
# echo $((05+1))
6
# echo $((06+1))
7
# echo $((07+1))
8
# echo $((08+1))
arithmetic expression: syntax error: "08+1"
# echo $((09+1))
arithmetic expression: syntax error: "09+1"
# echo $((10+1))
11
This is down to the following in arity_lex.l rev 1.11 and later:
0x[0-9a-fA-F]+ { yylval = strtol(yytext, 0, 16); return(ARITH_NUM); }
0[0-7]* { yylval = strtol(yytext, 0, 8); return(ARITH_NUM); }
[1-9][0-9]* { yylval = strtol(yytext, 0, 10); return(ARITH_NUM); }
I see from the 1.11 commit this is to recognise octal and hex, but must a
leading zero always indicate octal?
--
Stephen