Home > Enterprise >  token recognition shell quote empty
token recognition shell quote empty

Time:10-01

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)$

CodePudding user response:

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"};
  • Related