Skip to content

Commit

Permalink
support quoting
Browse files Browse the repository at this point in the history
Under quotes, the `<`, `|`, `>` and alike have no special meaning.
  • Loading branch information
stsp committed Jul 17, 2024
1 parent 7ff153d commit 8c5ab9a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -4023,6 +4023,7 @@ static void parse_cmd_line(void)
char *extr, *dest, *saved_extr, *delim;
char new_cmd_line[MAX_CMD_BUFLEN], *end;
const char *v;
int quoting;

// substitute in variable values before parsing
extr = strchr(cmd_line, '%');
Expand Down Expand Up @@ -4118,25 +4119,37 @@ static void parse_cmd_line(void)
pipe_to_cmd[0] = '\0'; // |
pipe_to_cmd_redir_count = 0; // count of '|' characters

quoting = 0;
extr = cmd_line;
while (*extr != '\0')
{
c = *extr;
switch (*extr)
{
case '\"':
quoting ^= 1;
c = 0;
break;
case '<':
if (quoting)
goto quot;
dest = pipe_file[STDIN_INDEX];
pipe_count_addr = &(pipe_file_redir_count[STDIN_INDEX]);
break;
case '>':
if (quoting)
goto quot;
dest = pipe_file[STDOUT_INDEX];
pipe_count_addr = &(pipe_file_redir_count[STDOUT_INDEX]);
break;
case '|':
if (quoting)
goto quot;
dest = pipe_to_cmd;
pipe_count_addr = &pipe_to_cmd_redir_count;
break;
default:
quot:
c = 0;
break;
}
Expand Down

0 comments on commit 8c5ab9a

Please sign in to comment.