newlife
newlife

Reputation: 778

What does the " \'" mean in splitting a command line?

int parseline(const char *cmdline, char **argv)
{
    static char array[MAXLINE]; /* holds local copy of command line */
    char *buf = array;          /* ptr that traverses command line */
    char *delim;                /* points to first space delimiter */
    int argc;                   /* number of args */
    int bg;                     /* background job? */

    strcpy(buf, cmdline);
    buf[strlen(buf)-1] = ' ';  /* replace trailing '\n' with space */
    while (*buf && (*buf == ' ')) /* ignore leading spaces */
        buf++;

    /* Build the argv list */
    argc = 0;
    if (*buf == '\'') {
        buf++;
        delim = strchr(buf, '\'');
    }
    else {
        delim = strchr(buf, ' ');
    }

//...
}

The part I don't understand is if (*buf == '\'').

What I know about this part is to split command line with a delimiter, and the latter one is space, then what the \' mean?

Upvotes: 0

Views: 55

Answers (1)

MrRobot
MrRobot

Reputation: 82

'\'' is an escaped single quote

see here for more escape sequences

Upvotes: 1

Related Questions