c++ - separate shell command with some symbols -


i implementing shell using c++ coding language.

basically define char *argv[128] storing command strtok space.

so if input ls -a -l > test.txt turn

ls -a -l > test.txt 

what want separate '>' symbol can continue implement redirection , pipe function.

well want define vector store ls-a-l , test.txt , let program redirection function.

how can that?

you should define lexical conventions shell. instance in posix shells can pass argument space e.g. quoting or escaping backslash, in
ls > 'file name spaces' output of ls single file named file name spaces

if coding in c++, should use genuine c++ features. read line std::string using std::getline. should tokenize string, i.e. transform sequence of tokens. tokens special (so > not same quoted '>' etc...). define class token , implement parser gives std::vector<token> line (of type std::string) have read.

of course you'll need know syscalls, read e.g. advanced linux programming. instance, cd has shell builtin calls chdir(2). redirections need use dup2(2) , open(2). pipes need use pipe(2) etc....

btw, should source code of free software shells (and use strace find out do). coded in c (e.g. gnu bash, or sash), fish coded in c++.