aboutsummaryrefslogtreecommitdiffstats
path: root/src/run
diff options
context:
space:
mode:
Diffstat (limited to 'src/run')
-rw-r--r--src/run/mod.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/run/mod.rs b/src/run/mod.rs
index 4970792..f32007e 100644
--- a/src/run/mod.rs
+++ b/src/run/mod.rs
@@ -229,8 +229,24 @@ impl parse::Expander for Executor {
type Error = ExecError;
fn expand_var(&mut self, var: BString) -> Result<BString, Self::Error> {
+ if var.is_empty() {
+ return Err(ExecError::UnknownVariable(var));
+ }
+
+ if var[0].is_ascii_digit() {
+ if let Some(x) = String::from_utf8(var.clone())
+ .ok()
+ .and_then(|x| x.parse::<usize>().ok())
+ {
+ match std::env::args_os().skip(x).next() {
+ Some(arg) => return Ok(arg.into_encoded_bytes()),
+ None => (),
+ }
+ }
+ }
+
if let Some(val) = self.se.lock().unwrap().vars.get(&var) {
- return Ok(val.clone())
+ return Ok(val.clone());
}
match std::env::var_os(OsStr::from_bytes(&var)) {