diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-01-10 00:16:22 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-01-10 00:16:22 -0500 |
commit | b5d2a84fa76b054073b0b459a2304706c6683c55 (patch) | |
tree | 6d5bbb9182a61b428cf6efe13cd1bd6039ec8a35 /src/parse | |
parent | feb932105426a9c9f7ab861dbdf2c2ab813b1f6a (diff) | |
download | nbsh-b5d2a84fa76b054073b0b459a2304706c6683c55.tar.gz nbsh-b5d2a84fa76b054073b0b459a2304706c6683c55.zip |
also support it for output fds
Diffstat (limited to 'src/parse')
-rw-r--r-- | src/parse/ast.rs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/parse/ast.rs b/src/parse/ast.rs index 4c65c6a..d331863 100644 --- a/src/parse/ast.rs +++ b/src/parse/ast.rs @@ -242,12 +242,7 @@ impl Redirect { super::Direction::Out | super::Direction::Append => 1, } } else { - match from { - "in" => 0, - "out" => 1, - "err" => 2, - _ => from.parse().unwrap(), - } + parse_fd(from) }; Self { from, to, dir } } @@ -256,7 +251,7 @@ impl Redirect { let to = if self.to.parts.len() == 1 { if let WordPart::Bareword(s) = &self.to.parts[0] { if let Some(fd) = s.strip_prefix('&') { - super::RedirectTarget::Fd(fd.parse().unwrap()) + super::RedirectTarget::Fd(parse_fd(fd)) } else { super::RedirectTarget::File(std::path::PathBuf::from( self.to.eval(env), @@ -346,6 +341,15 @@ fn strip_basic_escape(s: &str) -> String { new } +fn parse_fd(s: &str) -> std::os::unix::io::RawFd { + match s { + "in" => 0, + "out" => 1, + "err" => 2, + _ => s.parse().unwrap(), + } +} + #[cfg(test)] #[path = "test_ast.rs"] mod test; |