fix echo debashify
This commit is contained in:
parent
e61a2e9c85
commit
06eac33b0a
3 changed files with 37 additions and 7 deletions
|
|
@ -23,8 +23,9 @@ arg* copy(arg* in);
|
|||
variable* copy(variable* in);
|
||||
|
||||
// testers
|
||||
|
||||
bool arg_has_char(char c, arg* in);
|
||||
bool possibly_expands(arg* in);
|
||||
bool possibly_expands(arglist* in);
|
||||
|
||||
// modifiers
|
||||
void force_quotes(arg* in);
|
||||
|
|
|
|||
|
|
@ -215,6 +215,8 @@ bool debashify_echo(pipeline* pl)
|
|||
{
|
||||
delete in->args->args[0];
|
||||
in->args->args[0] = new arg("printf");
|
||||
if(possibly_expands(in->args->args[2]) )
|
||||
{
|
||||
in->args->insert(1, new arg("%s\\ "));
|
||||
if(newline) // newline: add a newline command at the end
|
||||
{
|
||||
|
|
@ -224,6 +226,17 @@ bool debashify_echo(pipeline* pl)
|
|||
pl->cmds[0] = br;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string printfarg="'%s";
|
||||
for(uint32_t i=2; i<in->args->size(); i++)
|
||||
printfarg+=" %s";
|
||||
if(newline)
|
||||
printfarg+="\\n";
|
||||
printfarg+="'";
|
||||
in->args->insert(1, new arg(printfarg));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,6 +115,22 @@ bool arg_has_char(char c, arg* in)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool possibly_expands(arg* in)
|
||||
{
|
||||
for(auto it: in->sa)
|
||||
if( (it->type == _obj::subarg_subshell || it->type == _obj::subarg_variable ) && it->quoted == false)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool possibly_expands(arglist* in)
|
||||
{
|
||||
for(auto it: in->args)
|
||||
if(possibly_expands(it))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// ** CLASS EXTENSIONS ** //
|
||||
|
||||
/// GETTERS ///
|
||||
|
|
|
|||
Loading…
Reference in a new issue