Implement SHLVL tracking, LINENO variable, and magic shell variables (SECONDS, EPOCHREALTIME, EPOCHSECONDS, RANDOM)

This commit is contained in:
2026-03-08 00:30:22 -05:00
parent 07d7015dd4
commit a464540fbe
3 changed files with 72 additions and 2 deletions

View File

@@ -258,6 +258,9 @@ impl Dispatcher {
Ok(())
}
pub fn dispatch_cmd(&mut self, node: Node) -> ShResult<()> {
let (line, _) = node.get_span().clone().line_and_col();
write_vars(|v| v.set_var("LINENO", VarKind::Str((line + 1).to_string()), VarFlags::NONE))?;
let Some(cmd) = node.get_command() else {
return self.exec_cmd(node); // Argv is empty, probably an assignment
};