On Fri, 17 Dec 2021 11:18:26 +0100
Martijn Dekker <martijn@inlv.demon.nl> wrote:
What the announcement item above means instead is this:
$ myfunc() { return 12345; }
$ myfunc; echo $?
12345
$ (myfunc); echo $?
57
$ ksh -c 'myfunc() { return 12345; }; myfunc'; echo $?
57
i.e., the exit status of a subshell or child shell that invokes
'myfunc', and does nothing to overwrite $? before exiting, is the least
significant 8 bits of 12345, i.e., 12345 % 0xFF == 210.
For the least significant 8 bits of 12345 the calculation you want is
12345 % 256 == 57 .Regardless , 12345 % 0xFF == 105 .
If you want to use 255 (i.e., hex FF), then you have to use an 'and' operator.
i.e., either of:
12345 % 256
or:
12345 & 255
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 422 |
Nodes: | 16 (3 / 13) |
Uptime: | 196:31:31 |
Calls: | 8,951 |
Calls today: | 2 |
Files: | 13,352 |
Messages: | 5,992,474 |