Skip to content

Commit 7ed18f1

Browse files
committed
Improve algorithm
1 parent ea48b29 commit 7ed18f1

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/core.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,11 @@ impl ShellCore {
250250
self.data.set_layer_array("PIPESTATUS", &pipestatus, 0);
251251

252252
if self.options.query("pipefail") {
253-
let mut rightmost_nonzero = "0".to_string();
254-
for e in &pipestatus {
255-
if e != "0" {
256-
rightmost_nonzero = e.to_string();
257-
}
253+
pipestatus.retain(|e| e != "0");
254+
255+
if pipestatus.len() != 0 {
256+
self.data.set_param("?", &pipestatus.last().unwrap());
258257
}
259-
self.data.set_param("?", &rightmost_nonzero);
260258
}
261259

262260
if exclamation {

0 commit comments

Comments
 (0)