Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ breaking entries are marked **BREAKING**.
an `ExecContext` can spawn a child with the kernel's external-command
discipline. `tools::DEFAULT_KILL_GRACE` is 2s. Only a struct literal changes.

- **Arithmetic diverges from bash on purpose** — overflow, an unset/empty
operand, and a leading zero are errors, never a wrap or 0; strings are
values, not expressions; a skipped `&&`/`||`/`?:` branch's `$(...)` never
runs.

### Added
- **`random` builtin** — `random [--min N] [--max N]` prints one uniformly
chosen integer, typed; the default range is bash's `$RANDOM` (0 to 32767).
- **`$(( ))` reads another base** (`0x`, `base#digits`, `base#$var`) and
does checked 64-bit arithmetic with the full C operator set through `?:`;
`$(...)` is an operand; bare `(( expr ))` is a condition, like `[[ ]]`.

- **Wrapped commands** (`kaish_kernel::tools::wrapped`, `subprocess` feature):
register an external program as a tool with a declared grammar. Verbs and flags
Expand Down
17 changes: 13 additions & 4 deletions crates/kaish-help/content/en/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,21 @@ DATA=$(kaish-last) # capture for later use
## Arithmetic

```sh
X=$((5 + 3)) # 8
Y=$((X * 2)) # 16
# Operators: + - * / % > < >= <= == !=
# Comparisons return 1/0
echo $((5 + 3 * 2)) # 11 checked 64-bit integers; overflow is an error
echo $((0xff)) # 255 hex; also $((16#ff)) — base#digits, base 2 to 36
echo $((8#17)) # 15 octal; $((010)) is an error — write 8#10 or 10
m=$(date +%m); echo $((10#$m + 1)) # text with a leading zero, read as decimal
echo $((2 ** 10)) # 1024
echo $((5 > 3)) # 1 comparisons return 1 or 0
echo $((a > b ? a : b)) # ternary; && || ? : skip the side they do not need
echo $(( $(wc -l < f) * 2 )) # $(cmd) is an operand
x=$((x + 1)) # assignment stays outside; x++ is an error
while (( i <= 5 )); do ...; done # (( )) alone is a condition
```

Operators, highest first: `+ - ! ~` · `**` · `* / %` · `+ -` · `<< >>` · `< <= > >=` · `== !=` · `&` · `^` · `|` · `&&` · `||` · `? :`.
An unset variable, a float, or `$RANDOM` is an error that names the fix.

## Functions

```sh
Expand Down
19 changes: 14 additions & 5 deletions crates/kaish-help/src/fragments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,11 +645,20 @@ DATA=$(kaish-last) # capture for later use
"arithmetic",
"Arithmetic",
r#"```sh
X=$((5 + 3)) # 8
Y=$((X * 2)) # 16
# Operators: + - * / % > < >= <= == !=
# Comparisons return 1/0
```"#,
echo $((5 + 3 * 2)) # 11 checked 64-bit integers; overflow is an error
echo $((0xff)) # 255 hex; also $((16#ff)) — base#digits, base 2 to 36
echo $((8#17)) # 15 octal; $((010)) is an error — write 8#10 or 10
m=$(date +%m); echo $((10#$m + 1)) # text with a leading zero, read as decimal
echo $((2 ** 10)) # 1024
echo $((5 > 3)) # 1 comparisons return 1 or 0
echo $((a > b ? a : b)) # ternary; && || ? : skip the side they do not need
echo $(( $(wc -l < f) * 2 )) # $(cmd) is an operand
x=$((x + 1)) # assignment stays outside; x++ is an error
while (( i <= 5 )); do ...; done # (( )) alone is a condition
```

Operators, highest first: `+ - ! ~` · `**` · `* / %` · `+ -` · `<< >>` · `< <= > >=` · `== !=` · `&` · `^` · `|` · `&&` · `||` · `? :`.
An unset variable, a float, or `$RANDOM` is an error that names the fix."#,
),
syntax_section(
"functions",
Expand Down
Loading