I have implemented a bash like shell in c language. I support < > >> ; | and &. My next task is to add a support for ( and ) basically a subshell. How can we implement a subshell. I can fork and put parent on wait, pass environment variables but I need to add support to commands like (ls | sort) ; ls (I admit that the command does not make much sense but it explains the motive)
Any help is appreciated.
TO implement this we parse the command line and make a tree like structure. This can be done with the help of
lexandyaccand as barmer suggested we can name each node assubshellpipelinesemicolon. After parsing the whole command line pass the pointer to the whole node to the main program. To run a subshellforkand then reload the same program usingexecvepassing the current environment.