menios
menios copied to clipboard
Port xargs utility to meniOS
Description
Port the xargs utility to meniOS to enable building and executing commands from standard input, making it possible to chain commands effectively in pipelines.
Requirements
Implement a basic xargs utility with essential functionality:
-
xargs COMMAND- Read items from stdin and execute COMMAND with them as arguments - Default behavior: pass all items as arguments to a single command invocation
- Handle multiple arguments per command invocation
- Basic flags (optional):
-
-n MAX- Use at most MAX arguments per command line -
-I REPLACE- Replace occurrences of REPLACE in COMMAND with names read from stdin -
-t- Print the command line before executing it -
-p- Prompt before executing each command
-
Implementation Details
The utility should:
- Read input from stdin (whitespace or newline delimited)
- Build command lines from the input
- Use
fork()andexecve()to execute commands - Handle proper exit status aggregation
- Work with the existing process management syscalls
- Handle edge cases (empty input, command failures, argument list too long)
Usage Examples
$ echo "file1.txt file2.txt file3.txt" | xargs cat
(concatenates all three files)
$ find /tmp -name "*.tmp" | xargs rm
(removes all .tmp files found)
$ echo "world" | xargs -I {} echo "Hello, {}"
Hello, world
$ ls *.c | xargs -n 1 gcc -c
(compiles each .c file separately)
Dependencies
- #193 - Minimal userland libc ✅ (COMPLETE)
- #93 - Fork/exec process creation ✅ (COMPLETE)
- #102 - Pipes implementation ✅ (COMPLETE - for pipeline support)
Acceptance Criteria
- [ ]
xargs COMMANDexecutes command with stdin items as arguments - [ ] Basic argument batching works (handle whitespace/newlines)
- [ ] Works in pipelines with other utilities
- [ ] Proper exit status handling
- [ ]
-nflag for limiting arguments per invocation (optional) - [ ]
-Iflag for replacement strings (optional) - [ ] Test coverage for xargs functionality
- [ ] Documentation/man page entry
Estimated Effort
2-3 days
Priority
Medium - Very useful for composing complex command pipelines
Milestone
Consider for future utility expansion after Mosh milestone completion