Tasks
This document contains the main tasks for enhancing the Pintos shell functionality. Each task focuses on implementing robust shell commands with proper argument handling.
Prerequisites
Before starting these tasks, ensure you have:
Basic understanding of shell programming concepts
Successfully completed the environment setup
Access to the Pintos development environment
Git Workflow Setup
Important: Follow this Git workflow to avoid merge conflicts and ensure proper submission:
1. Update Your Repository
Start by pulling the latest changes from the public repository:
git pull public main
2. Create and Switch to Shell Branch
Create a dedicated branch for your shell implementation:
git checkout -b shell
3. Development Workflow
Always work in the
shell
branch - never push directly tomain
Make commits regularly with descriptive messages
Push your changes to the
shell
branch when ready
4. Submission Requirements
Submissions will only be accepted from the
shell
branchNo submissions from merge branches or main branch
Direct pushes to main can cause merge conflicts in future updates
5. Example Commands
# After making changes
git add .
git commit -m "Implement robust echo command with argument handling"
git push origin shell
# To continue working later
git checkout shell
git pull origin shell
Task 1: Implement Robust echo Command
Objective: Implement a robust echo command that handles various argument types and edge cases gracefully.
Requirements
The echo command should:
Handle no arguments gracefully (exit with status 0)
Process multiple arguments correctly
Handle arguments with special characters (quotes, backslashes, tabs)
Process arguments with leading/trailing spaces
Handle newline and carriage return characters in arguments
Process dash-prefixed arguments (--help, -n, --version)
Testing Scenarios
Your implementation should pass these test cases:
echo-none: No arguments - should exit successfully
echo-multi: Multiple arguments, mixed content, many arguments
echo-mixed: Arguments with leading/trailing whitespace
echo-newlines: Arguments containing newline and carriage return characters
echo-dashes: Arguments starting with dashes
Expected Behavior
Refer to the .ck
files in the tests/shell
folder.
Task 2: Implement touch Command
Objective: Implement a touch
command that creates empty files.
Requirements
Create a new
touch
command that accepts a filename as an argumentThe command should create an empty file if it doesn't exist
If the file already exists, the command should succeed (no error)
The command should exit with status 0 on success
Testing
Your implementation should pass the touch-create test:
Running
touch newfile.txt
should create an empty fileThe shell should report success and exit with status 0
The created file should exist and be empty (0 bytes)
Expected Behavior
$ touch newfile.txt
newfile.txt: created
touch: exit(0)
$ ls
newfile.txt
$ cat newfile.txt
(empty file)
Implementation Notes
Source Code Location
The echo
and touch
commands are located in the pintos/src/examples/
folder:
echo.c
- Source code for the echo commandtouch.c
- Source code for the touch command
Building the Commands
Compile the example commands first:
cd pintos/src/examples make
This will compile
echo
andtouch
executables that will be used by the userprog tests.Build the userprog kernel:
cd ../userprog make
Rebuilding After Changes
Since this is a compiled language, you must rebuild after making any changes to the source code:
After modifying echo.c or touch.c:
cd pintos/src/examples make
After modifying shell.c or other userprog files:
cd pintos/src/userprog make
Clean Builds
If you encounter build issues or want to ensure a fresh build:
Clean examples:
cd pintos/src/examples make clean make
Clean userprog:
cd pintos/src/userprog make clean make
Note: Always run make
in both directories after making changes to ensure your modifications are compiled and available for testing.
Testing
For comprehensive testing information, see the Testing Guide.
Navigate to the build directory:
cd pintos/src/userprog/build
Run all tests:
make check
Run specific shell tests:
make tests/shell/echo-none.result make tests/shell/echo-multi.result make tests/shell/echo-mixed.result make tests/shell/echo-newlines.result make tests/shell/echo-dashes.result make tests/shell/touch-create.result
Note: The testing guide contains additional information about debugging test failures, verbose output, simulator selection, and best practices for test-driven development.
Shell Robustness
All commands should handle malformed input gracefully
Prevent buffer overflows and memory corruption
Return appropriate exit codes
Handle extreme input patterns safely
Last updated