diff --git a/src/generate.cpp b/src/generate.cpp index bb472c7..1865bbf 100644 --- a/src/generate.cpp +++ b/src/generate.cpp @@ -132,9 +132,10 @@ std::string redirect_t::generate(int ind) std::string ret=op; if(target!=nullptr) { - if(!opt_minify) + std::string targetret=target->generate(0); + if(!(opt_minify && !is_in(targetret[0], "<>"))) ret += ' '; - ret += target->generate(0); + ret += targetret; } return ret; } diff --git a/src/parse.cpp b/src/parse.cpp index 3b6571f..9131f3f 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -664,6 +664,18 @@ parse_context parse_heredocument(parse_context ctx) return ctx; } +std::pair parse_bash_procsub(parse_context ctx) +{ + if(!ctx.bash) + { + parse_error(strf("bash specific: %c()", ctx[ctx.i]), ctx); + } + bool is_output = ctx[ctx.i] == '>'; + ctx.i+=2; + auto ps = parse_subshell(ctx); + return std::make_pair(new arg_t(new subarg_procsub_t(is_output, ps.first)), ps.second); +} + std::pair parse_redirect(parse_context ctx) { bool is_redirect=false; @@ -789,8 +801,12 @@ std::pair parse_redirect(parse_context ctx) } else { - auto pa = parse_arg(ctx); - ret->target = pa.first; + std::pair pa; + if(ctx.i+1 < ctx.size && (ctx[ctx.i] == '<' || ctx[ctx.i] == '>') && ctx[ctx.i+1] == '(' ) // bash specific <() + pa = parse_bash_procsub(ctx); + else + pa = parse_arg(ctx); + ret->target=pa.first; ctx=pa.second; } } @@ -860,17 +876,11 @@ std::pair parse_arglist(parse_context ctx, bool hard_ { if(ctx.i+1 < ctx.size && (ctx[ctx.i] == '<' || ctx[ctx.i] == '>') && ctx[ctx.i+1] == '(' ) // bash specific <() { - if(!ctx.bash) - { - parse_error(strf("bash specific: %c()", ctx[ctx.i]), ctx); - } - bool is_output = ctx[ctx.i] == '>'; - ctx.i+=2; + auto pa=parse_bash_procsub(ctx); if(ret == nullptr) ret = new arglist_t; - auto ps = parse_subshell(ctx); - ret->add(new arg_t(new subarg_procsub_t(is_output, ps.first))); - ctx=ps.second; + ret->add(pa.first); + ctx=pa.second; } else if(redirs!=nullptr) { diff --git a/test/a.bash b/test/a.bash index 85dd7ed..497e16c 100644 --- a/test/a.bash +++ b/test/a.bash @@ -41,3 +41,7 @@ echo ${!BAR} a=a [[ $a = a && foo = fo* && bar =~ b.r || 2 < 3 ]] + +for I in A B C ; do + echo "$I" +done > >(cat)