diff --git a/examples/not.ion b/examples/not.ion new file mode 100644 index 0000000000000000000000000000000000000000..ef5f4b36825f601c570f9d6a617c9d0e877226ab --- /dev/null +++ b/examples/not.ion @@ -0,0 +1,6 @@ +not true || echo not true +not false && echo not false +true && not false && echo true and not false +not test -z "a" && echo not test +not echo hello +echo $? \ No newline at end of file diff --git a/examples/not.out b/examples/not.out new file mode 100644 index 0000000000000000000000000000000000000000..fa385d520605fe79427c950fae3d915625000dfc --- /dev/null +++ b/examples/not.out @@ -0,0 +1,6 @@ +not true +not false +true and not false +not test +hello +-1 diff --git a/src/builtins/mod.rs b/src/builtins/mod.rs index d87aa62748c2722ec4a1b650204073e0b1837e60..60ea45d61e0b9734434efe34b07b9692e03fc570 100644 --- a/src/builtins/mod.rs +++ b/src/builtins/mod.rs @@ -193,6 +193,20 @@ impl Builtin { }); /* Misc */ + commands.insert("not", + Builtin { + name: "not", + help: "Reverses the exit status value of the given command.", + main: Box::new(|args: &[&str], shell: &mut Shell| -> i32 { + let cmd = args[1..].join(" "); + shell.on_command(&cmd); + match shell.previous_status { + SUCCESS => FAILURE, + FAILURE => SUCCESS, + _ => shell.previous_status + } + }), + }); commands.insert("set", Builtin { name: "set",