Name: Sayali Kulkarni
CS Login: sskulkarni34
Email: sskulkarni34@wisc.edu
- Interactive mode: Implemented (
wsh>prompt shown only when stdin is a terminal). - Batch mode: Implemented (reads commands from file, no prompt, exits on EOF).
- External commands: Implemented using
fork(),execv(),waitpid(). - PATH resolution: Implemented manually using
getenv("PATH"), tokenizing on:, and checking executability withaccess(..., X_OK).- If
PATHis unset/empty, defaults to/bin. - If the command contains
/, it is treated as a path and executed directly.
- If
- Built-ins: Implemented
exit(ignores args)cd [dir](defaults to$HOME, printscd: HOME not setif missing, usesperror("cd")on failure)env [VAR=val](no args prints all env vars;env VAR=valsets;env VARsets empty string)
- Environment variable substitution: Implemented via
get_variable()hook used by the provided parser.- If variable is not set, returns empty string.
- Pipelines: Implemented for arbitrary-length pipelines using
pipe(),dup2(), andfork()per command.- Built-ins inside a pipeline run in the child (so they do not affect the parent shell state).
- Parent waits for all pipeline children; shell status is set from the last command in the pipeline.
- Uses the provided parser (
parse_input()) to split input into:- pipelines separated by
; - pipeline commands separated by
| - argv arrays for each command
- pipelines separated by
- Prompt behavior:
wsh>is printed only ifisatty(STDIN_FILENO)is true.
- Memory management:
- Input line is read using
getline()to support arbitrary-length lines. - Parsed command lines are freed with
free_command_line()after execution. - Any heap allocations used for PATH resolution are freed after use.
- Input line is read using
- Invalid usage: prints
Usage: ./wsh [file]and exits(1). - Batch file open failure: uses
perror("fopen")and exits(1). - System call failures: checked and reported with
perror()(e.g.,fork,pipe,dup2,setenv,malloc/strdupwhere applicable). - Command not found:
- If a command cannot be resolved in PATH (or exec fails), prints
Command not foundtostderr.
- If a command cannot be resolved in PATH (or exec fails), prints
- Empty lines/comments:
- Empty/invalid parse results are ignored and the shell continues.
From the project root (inside the CS537 Docker environment):
make./wsh./wsh path/to/batchfile.txtcd tests
./run-tests.shInteractive:
valgrind --leak-check=full --track-origins=yes ./wshBatch:
valgrind --leak-check=full --track-origins=yes ./wsh tests/inputs/some_batch_file.txt- The implementation relies on the provided parser’s assumptions and limits (e.g.,
MAX_ARGS). cdonly affects the parent shell when executed as a standalone command (not in a pipeline), as required.