diff --git a/libr/core/cmd.c b/libr/core/cmd.c index e423951cda4a7..85e6c7530047d 100644 --- a/libr/core/cmd.c +++ b/libr/core/cmd.c @@ -4059,7 +4059,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek p = strchr (p + 1, ';'); } } - if (p && *p && p[1] == '>') { + if (R_STR_ISNOTEMPTY (p) && p[0] != '<' && p[1] == '>') { str = p + 2; while (*str == '>') { str++; @@ -4278,6 +4278,13 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek /* pipe console to file */ ptr = (char *)r_str_firstbut (cmd, '>', "\""); // TODO honor ` + if (ptr + 2 > cmd) { + // Handle ~<> + char *prev = ptr - 2; + if (r_str_startswith (prev, "~<>")) { + ptr = NULL; + } + } if (ptr) { if (ptr > cmd) { char *ch = ptr - 1; diff --git a/test/db/cmd/cons_grep b/test/db/cmd/cons_grep index f45c2c28e8b91..d84a4da78a1cb 100644 --- a/test/db/cmd/cons_grep +++ b/test/db/cmd/cons_grep @@ -623,3 +623,26 @@ EXPECT=<hehbold +psz~<> +EOF +EXPECT=< + + + heh + + + + bold + + + + +EOF +RUN