From f5e5d32eca300f47b1bd912bbf478345cc529560 Mon Sep 17 00:00:00 2001 From: zawz Date: Sun, 28 Feb 2021 14:15:36 +0100 Subject: [PATCH] implement bash specific ${!var} --- src/debashify.cpp | 11 +++++++++++ src/parse.cpp | 8 ++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/debashify.cpp b/src/debashify.cpp index b69feb1..d4f9393 100644 --- a/src/debashify.cpp +++ b/src/debashify.cpp @@ -766,12 +766,23 @@ bool debashify_procsub(list* lst, debashify_params* params) 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; +} + bool r_debashify(_obj* o, debashify_params* params) { // global debashifies debashify_array_arithmetic(o, params); switch(o->type) { + case _obj::_variable: { + variable* t = dynamic_cast(o); + debashify_var(t, params); + } break; case _obj::_arg: { arg* t = dynamic_cast(o); debashify_array_get(t, params); diff --git a/src/parse.cpp b/src/parse.cpp index 9ad8f41..aa3ec29 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -282,9 +282,13 @@ std::pair parse_manipulation(const char* in, uint32_t size, { #endif ; - if(in[i] == '#') + if(in[i] == '#' || in[i] == '!') { - precede = new arg("#"); + if(!g_bash && in[i] == '!') + throw PARSE_ERROR("bash specific: '${!}'", i); + std::string t; + t+=in[i]; + precede = new arg( t ); i++; }