This is a custom implementation of the Linux Command Line called mysh.
| Command | Description |
|---|---|
make mysh |
Creates the executable file mysh. Run it using ./mysh. |
make testJobMaking |
Tests the job creation logic. See the Interactive Test section. |
make batchmodetest |
Compiles dependencies and runs test.sh in batch mode. |
make removeTXTFiles |
Cleans up .txt files generated during batch mode testing. |
make clean |
Removes all .o, mysh executable, and .dSYM files. |
Note on Naming: If
makefails, ensure the file is named exactlyMakefileorMakeFileas per your system's case sensitivity.Debugging: Edit the Makefile and change line 2 to
DEBUG = -D DEBUG=1to enable verbose debug information. Use the-Bflag with any command to force a rebuild.
- Interactive Mode: Used to run one command at a time via user input.
- Batch Mode: Used to run a sequence of commands from a file until the
exitcommand or EOF (End of File) is reached.
- Buffered Commands (e.g.,
less): On ilab, scrolling past the EOF inlessmay cause random characters to be printed tomyshafter quitting. This occurs because the characters are sent to the tty whilemyshis still inexec(). - Quotes:
myshdoes not handle quotes; they are treated as literal characters. - Escaped Spaces:
myshdoes not support spaces in file/directory names (e.g.,\). - Conditionals: * In a pipe, the exit status depends on the last command in the pipe.
- In a single command, it depends on that command's status.
- Exiting: Any call to
exit(with or without arguments/pipes) will closemysh. However, the string "exit" used as a standard argument (e.g.,echo exit) will not trigger a shutdown. - Whitespace: All whitespace is ignored, including gaps between pipe symbols.
|ls|echo|is treated the same as| ls | echo |. - Constraints: Only single pipes are supported (no multi-pipe chains). Tab completion and up-arrow history are not implemented.
Represents the Job Abstract Data Type.
execPath:- Builtins: The name of the builtin.
- Non-builtins: Full path located via
/usr/local/bin,/usr/bin, or/bin. - If the input contains a
/, it is treated as a direct path.
args: Array of strings expanded using wildcards (*). Wildcards match zero or more characters and must appear at the end of a path.- Redirection: Stores paths for
inputReDirectPath(<) andoutputReDirectPath(>).
Handles core shell commands:
cd: Changes working directory viachdir(). Expects exactly one argument.which: Locates the path of a program. Checks builtins first, then system paths.pwd: Prints current working directory usinggetcwd().
The main program launcher.
- Manages
mysh_errnoto track exit statuses forthen/elselogic. - Execution Flow:
- Trim whitespace and split commands by pipes.
- Create
Jobobjects for each sub-command. - Single Job: If builtin, runs in-process with
dup2redirection. If non-builtin, usesfork(),dup2, andexec(). - Piped Jobs: Sets up communication using
pipe()anddup2().
Used to verify that mysh parses input, expansions, and redirections correctly.
Example Test Cases:
echo man name > txt.txt: Tests output redirection and bare name expansion.cat < txt.txt: Tests input redirection.ls *.c: Tests wildcard expansion for files in the current directory.ls testFolder2/*.txt > txt.txt: Tests wildcards within a specific path.
Run this using make batchmodetest. This suite covers:
- Wildcards: Including scenarios with no matching files (returns original string).
- Redirection: Input, output, and combined (e.g.,
./sum < in > out). - Pipes: Mixing system functions, builtins, and redirection within pipes.
- Conditionals: Verifying that
thenandelseblocks execute correctly based on the success of the preceding command.