From 733e6a572d9291ca1246a3f446eccb7508fe008e Mon Sep 17 00:00:00 2001 From: zawwz Date: Sat, 24 Jul 2021 19:34:12 +0200 Subject: [PATCH] add debashify variable substitution --- src/debashify.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/debashify.cpp b/src/debashify.cpp index b7a3bdf..552afeb 100644 --- a/src/debashify.cpp +++ b/src/debashify.cpp @@ -825,10 +825,34 @@ bool debashify_procsub(list* lst, debashify_params* params) return has_replaced; } +bool debashify_variable_substitution(arg* in, debashify_params* params) +{ + bool has_replaced=false; + for(uint32_t i=0; isa.size(); i++) + { + if(in->sa[i]->type == _obj::subarg_variable) + { + variable* v = dynamic_cast(in->sa[i])->var; + if(v->is_manip && v->precedence && v->manip->string() == "!") + { + arg* eval_arg = new arg; + eval_arg->add(new string_subarg("echo \\\"\\${")); + eval_arg->add(new variable_subarg(new variable(v->varname))); + eval_arg->add(new string_subarg("}\\\"")); + cmd* eval_cmd = make_cmd(std::vector({new arg("eval"), eval_arg})); + subshell_subarg* r = new subshell_subarg(new subshell(eval_cmd)); + r->quoted = in->sa[i]->quoted; + delete in->sa[i]; + in->sa[i] = r; + has_replaced=true; + } + } + } + return has_replaced; +} + bool debashify_var(variable* in, debashify_params* params) { - if(in->is_manip && in->precedence && in->manip->string() == "!") - throw std::runtime_error("Cannot debashify ${!VAR}"); return false; } @@ -845,6 +869,7 @@ bool r_debashify(_obj* o, debashify_params* params) case _obj::_arg: { arg* t = dynamic_cast(o); debashify_subarg_replace(t, params); + debashify_variable_substitution(t, params); } break; case _obj::_list: { list* t = dynamic_cast(o);