Exercise on C and system programming.
$ make clean; make all
$ ./psh
- Enable to redirect
- e.g.)
<command> > <filename>
- e.g.)
- Enable to pipe
- e.g.)
<command 1> | <command 2>
- Pipe should enable to be nested
- e.g.)
<command 1> | <command 2> | <command 3> | ... <command n>
- Depth of nests can be limited by realistic restriction
- e.g.)
- e.g.)
- Enable to interpret
~
as a part of paths - Redirect and pipe can be recognized even if they have no space arround them
- Enable to deal with both absolute and relative path
- Enable to read environment variables
- Enable to modify environment variables (5 points)
- Enable to interpret back quoted commands and return its result to outer command (20 points)
- Enable to interpret
if
statements and loops (15 points)
<piped_commands> ::= <command> { '|' <piped_commands> }
<command> ::= <command_element> { <command> }
<redirect_in> ::= { <num> } '<' { '&' } <word>
<redirect_out> ::= { <num> } '>' { ('>' | '&') } <word>
<redirection> ::= <redirect_in>
| <redirect_out>
<redirection_list> ::= <redirection> { <redirection_list> }
<command_element> ::= <word>
| <env_assignment>
| <redirection_list>
<digit> ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
<alpha> ::= 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j'
| 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't'
| 'u' | 'v' | 'w' | 'x' | 'y' | 'z'
| 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J'
| 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T'
| 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z'
<alphanum> ::= (<alpha> | <num> | '_' ) { <alphanum> }
<special> ::= '!' | '"' | '#' | '%' | ''' | '(' | ')' | '*' | '+' | ','
| '-' | '.' | '/' | ':' | ';" | '?' | '@' | '[' | ']' | '&'
| '\' | '^' | '_' | '`' | '{' | '|' | '}'
<word> ::= (<env> | <letter> | <home>) { <word> }
<home> ::= '~' { <alphanum> }
<env> ::= '$' { '{' } <word> { '}' }
<num> ::= <digit> { <num> }
<env_assignment> ::= <alphanum> '=' <word>
<letter> ::= (<alphanum> | <special>) { <letter> }
Copyright (c) 2010 Taku Fukushima. All rights reserved.
psh is MIT Lisense