Search code examples
ctokenlexer

token recognition shell quote empty


I'm doing a shell from scratch. If I store all tokens in an array char**, what I supposed to put in a string of array char** when quote is empty?

Example:

input>echo "" "" "" | cat -e
output>(space)(space)(space)$

Solution

  • If you're mimicking POSIX shells then each "" would tokenize to an empty string. The pipeline as a whole should tokenize to:

    char *tokens[] = {"echo", "", "", "", "|", "cat", "-e"};