printenv: change exit code when variable not found

GNU printenv has this behavior
This commit is contained in:
Thomas Queiroz
2021-11-02 18:36:28 -03:00
parent f2a3a1f920
commit b157a73a1f
+8 -1
View File
@@ -45,13 +45,20 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
return Ok(());
}
let mut not_found = false;
for env_var in variables {
if let Ok(var) = env::var(env_var) {
print!("{}{}", var, separator);
} else {
not_found = true;
}
}
Ok(())
if not_found {
Err(1.into())
} else {
Ok(())
}
}
pub fn uu_app() -> App<'static, 'static> {