From 54e1491e6fa063e98efa0c47655f425d8c2e2a65 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Tue, 2 Feb 2016 21:57:42 -0500 Subject: [PATCH] fix if evaluation. --- command.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/command.cpp b/command.cpp index 4a91319..fee3a85 100644 --- a/command.cpp +++ b/command.cpp @@ -292,6 +292,12 @@ int begin_command::execute(Environment &env, const fdmask &fds, bool throwup) { namespace { + /* + * returns: + * <0 -> error + * 0 -> false + * >0 -> true + */ int evaluate(int type, const std::string &s, Environment &env) { @@ -360,8 +366,9 @@ int if_command::execute(Environment &env, const fdmask &fds, bool throwup) { { indent_helper indent(env); int tmp = evaluate(c->type, s, env); - if (tmp < 0) { ok = true; rv = tmp; } - else rv = c->execute(env, newfds); + if (tmp < 0) { ok = true; rv = tmp; continue; } + if (tmp == 0) continue; + rv = c->execute(env, newfds); } }