Assignment | linux shell代写 – 这是一个linux shell的练习题目
In this assignment, you will write a Unix shell like "bash" called "nush".
A shell operates as follows:
- Accept an optional script file as the first command line argument.
- If there’s no script, show a prompt. Your prompt should be "nush$ ". Command input is accepted on the same line after the prompt.
- Read one line of commands from either stdin or the script.
- Execute that line of commands.
- Repeat until EOF or an "exit" command.
Command lines are made up of:
- Programs to execute.
- Built-in commands.
- Command line arguments to programs / builtins.
Programs to Execute
nush$ head -n 2 /usr/share/dict/words
Given a program to execute, like "head" above, your shell will do three things:
- fork(), to create a new process.
- in the child process, exec(), to execute the requested program, passing through the three command line arguments
- in the parent process, wait() or waitpid(), to allow the program to finish before executing another command
nush$ cd tests
Some commands aren’t programs to execute, they’re things that the shell should handle itself. You should implement two of these:
- The "cd" command changes the current directory. This means calling chdir() to change the state of your shell process.
- The "exit" command exits the shell.
In bash, lots of commands that are available as programs are actually built-in for efficiency, like pwd, echo, etc. Your shell should just run these as programs.
nush$ sort tests/sample.txt | tail -n 3
Operators either modify the behavior of one command or chain together multiple commands into a single command line.
Your shell should support seven operators:
- Redirect input: sort < foo.txt
- Redirect output: sort foo.txt > output.txt
- Pipe: sort foo.txt | uniq
- Background: sleep 10 &
- And: true && echo one
- Or: true || echo one
- Semicolon: echo one; echo two
- C Source code.
- A Makefile that builds your program.
- In a gzipped tarball, in a "challenge01" directory.
- Your compiled binary, object files, or other build artifacts.
- The "tmp" directory created by the tests.
- Stray hidden files.
Your source code should pass clang-check with no warnings.
Check your program with valgrind to make sure you have no memory allocation issues.
This is the first challenge assignment. It’s not easy. Get a couple of tests to pass, and submit to make sure they pass the autograder. Then get a couple more tests to pass, etc.
The last couple tests are pretty hard. I expect less than half of the class to pass all the tests and get a 100%.
Expected time to complete this assignment with most test passing is 14 hours.