Hello. I realized there is no unsigned right shift in bash arithmetic expression, and thought maybe there is interest. This is a not even compile-tested diff against 5.1.16. (Using same tab/space as in surroundings.)
A nice Sunday i wish everyone. diff -Napru bash-5.1.orig/expr.c bash-5.1/expr.c --- bash-5.1.orig/expr.c 2022-07-16 19:35:21.900221532 +0200 +++ bash-5.1/expr.c 2022-07-16 19:37:23.243552559 +0200 @@ -32,7 +32,7 @@ "**" [(exponentiation)] "*", "/", "%" "+", "-" - "<<", ">>" + "<<", ">>", ">>>" "<=", ">=", "<", ">" "==", "!=" "&" @@ -41,7 +41,7 @@ "&&" "||" "expr ? expr : expr" - "=", "*=", "/=", "%=", "+=", "-=", "<<=", ">>=", "&=", "^=", "|=" + "=", "*=", "/=", "%=", "+=", "-=", "<<=", ">>=", ">>>=", "&=","^=","|=" , [comma] (Note that most of these operators have special meaning to bash, and an @@ -112,13 +112,14 @@ #define LOR 8 /* "||" Logical OR */ #define LSH 9 /* "<<" Left SHift */ #define RSH 10 /* ">>" Right SHift */ -#define OP_ASSIGN 11 /* op= expassign as in Posix.2 */ -#define COND 12 /* exp1 ? exp2 : exp3 */ -#define POWER 13 /* exp1**exp2 */ -#define PREINC 14 /* ++var */ -#define PREDEC 15 /* --var */ -#define POSTINC 16 /* var++ */ -#define POSTDEC 17 /* var-- */ +#define URSH 11 /* ">>>" Unsigned right SHift */ +#define OP_ASSIGN 12 /* op= expassign as in Posix.2 */ +#define COND 13 /* exp1 ? exp2 : exp3 */ +#define POWER 14 /* exp1**exp2 */ +#define PREINC 15 /* ++var */ +#define PREDEC 16 /* --var */ +#define POSTINC 17 /* var++ */ +#define POSTDEC 18 /* var-- */ #define EQ '=' #define GT '>' #define LT '<' @@ -578,6 +579,9 @@ expassign () case RSH: lvalue >>= value; break; + case URSH: + lvalue = (uintmax_t)lvalue >> value; + break; case BAND: lvalue &= value; break; @@ -837,7 +841,7 @@ expshift () val1 = exp3 (); - while ((curtok == LSH) || (curtok == RSH)) + while ((curtok == LSH) || (curtok == RSH) || (curtok == URSH)) { int op = curtok; @@ -846,8 +850,10 @@ expshift () if (op == LSH) val1 = val1 << val2; - else + else if (op == RSH) val1 = val1 >> val2; + else + val1 = (uintmax_t)val1 >> val2; lasttok = NUM; } @@ -1251,6 +1257,7 @@ _is_multiop (c) case LOR: case LSH: case RSH: + case URSH: case OP_ASSIGN: case COND: case POWER: @@ -1424,7 +1431,19 @@ readtok () } else if ((c == GT) && (c1 == GT)) { - if (*cp == '=') + if (*cp == GT) + { + cp++; + if (*cp == '=') + { + assigntok = URSH; /* a >>>= b */ + c = OP_ASSIGN; + cp++; + } + else + c = URSH; + } + else if (*cp == '=') { assigntok = RSH; /* a >>= b */ c = OP_ASSIGN; --steffen | |Der Kragenbaer, The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt)