Implemented heredocs and herestrings

This commit is contained in:
2025-03-09 00:34:49 -05:00
parent 4f58c1c3fd
commit 1808786313
14 changed files with 233 additions and 89 deletions

View File

@@ -75,6 +75,7 @@ pub fn echo(node: Node, shenv: &mut ShEnv) -> ShResult<()> {
}
shenv.collect_redirs(redirs);
log!(DEBUG,"{:?}",shenv.ctx().redirs());
shenv.ctx_mut().activate_rdrs()?;
write_out(formatted)?;

View File

@@ -8,43 +8,10 @@ pub fn pwd(node: Node, shenv: &mut ShEnv) -> ShResult<()> {
let mut pwd = shenv.vars().get_var("PWD").to_string();
pwd.push('\n');
if shenv.ctx().flags().contains(ExecFlags::NO_FORK) {
shenv.collect_redirs(redirs);
if let Err(e) = shenv.ctx_mut().activate_rdrs() {
eprintln!("{:?}",e);
exit(1);
}
if let Err(e) = write_out(pwd) {
eprintln!("{:?}",e);
exit(1);
}
exit(0);
} else {
match unsafe { fork()? } {
Child => {
if let Err(e) = shenv.ctx_mut().activate_rdrs() {
eprintln!("{:?}",e);
exit(1);
}
if let Err(e) = write_out(pwd) {
eprintln!("{:?}",e);
exit(1);
}
exit(0);
}
Parent { child } => {
shenv.reset_io()?;
let children = vec![
ChildProc::new(child, Some("echo"), Some(child))?
];
let job = JobBldr::new()
.with_children(children)
.with_pgid(child)
.build();
wait_fg(job, shenv)?;
}
}
}
shenv.collect_redirs(redirs);
shenv.ctx_mut().activate_rdrs()?;
write_out(pwd)?;
} else { unreachable!() }
Ok(())
}