diff --git a/src/lib/shell/variables.rs b/src/lib/shell/variables.rs index 9a6e9fb17808cb2f08b4211ebf88966e7cedc2ae..9357e267c00bf741eca220de46768b8c5999ca00 100644 --- a/src/lib/shell/variables.rs +++ b/src/lib/shell/variables.rs @@ -82,10 +82,14 @@ impl Variables { /// Create a new scope. If namespace is true, variables won't be droppable across the scope /// boundary - pub fn new_scope(&mut self, namespace: bool) { self.0.new_scope(namespace) } + pub fn new_scope(&mut self, namespace: bool) { + self.0.new_scope(namespace) + } /// Exit the current scope - pub fn pop_scope(&mut self) { self.0.pop_scope() } + pub fn pop_scope(&mut self) { + self.0.pop_scope() + } pub(crate) fn pop_scopes<'b>( &'b mut self, @@ -196,9 +200,10 @@ impl Variables { .map_err(|cause| Error::InvalidHex(variable.into(), cause))?; Ok((c as char).to_string().into()) } - Some(("env", variable)) => { - env::var(variable).map(Into::into).map_err(|_| Error::UnknownEnv(variable.into())) - } + Some(("env", variable)) => match env::var(variable) { + Ok(v) => Ok(v.into()), + Err(_) => Ok("".into()), + }, Some(("super", _)) | Some(("global", _)) | None => { // Otherwise, it's just a simple variable name. match self.get(name) { @@ -293,7 +298,9 @@ pub(crate) mod tests { impl Expander for VariableExpander { type Error = IonError; - fn string(&self, var: &str) -> Result<types::Str, IonError> { self.0.get_str(var) } + fn string(&self, var: &str) -> Result<types::Str, IonError> { + self.0.get_str(var) + } fn array( &self, @@ -311,7 +318,9 @@ pub(crate) mod tests { Ok(cmd.into()) } - fn tilde(&self, input: &str) -> Result<types::Str, Self::Error> { Ok(input.into()) } + fn tilde(&self, input: &str) -> Result<types::Str, Self::Error> { + Ok(input.into()) + } fn map_keys(&self, _name: &str) -> Result<types::Args, Self::Error> { Err(expansion::Error::VarNotFound)