To compile the project, run make in the terminal from the directory containing your source files and the Makefile. Then run ./mysh
To clean up object files and the executable, run make clean
Divided the code with 4 different c files. utils.c: Contains a function expand_wildcards which is responsible for expanding wildcard patterns. It opens the specified directory (or the current directory if no path is included in the pattern), reads directory entries, and matches them against a provided wildcard pattern.
parse.c:
Parses the command line using the Command structure.
It tokenizes the input command string, handles file redirection symbols (<, >), wildcard expansion. It also checks for special built-in commands like cd, pwd, exit, and which.
main.c:
This is the main driver file for the shell application.
execute.c:
Handles the execution of external commands with input and output redirection and piping between commands.
Has logic to fork processes for command execution, handle file redirections, and set up pipes for connecting multiple commands if needed.
Note: The file myscript.sh contains only echo hello
Note: the file multipleCommandsInBatch.sh contains commands ./testPipe < output.txt, cat output.txt | ./testPipe, and echo "hi"
- We entered
./mysh myscript.sh-> correctly printedhello. - We entered
cat myscript.sh | ./mysh-> correctly printedhello - We entered ./mysh multipleCommandsInBatch.sh -> correctly printed Pip: huh Pip: huh "hi"
- Entered
./mysh-> correctly printedWelcome to my shell! - Every input below had the starting prompt
mysh>
Want to check if correctly matches file/directories with _ in the current directory and won't accept a name that starts with a period for patterns that being with _
Note: We have a .txt file which doesn't have a name
- Entered
ls -l e*-> correctly listed files and directories that start with e - Entered
ls *o.txt-> correctly listed files and directories that ended with o.txt - Entered
ls *.txt-> correctly listed files and directories that end with .txt, which didn't include the file that began with a period (.txt)
Note: We have a c file named testPipe that takes in an argument and outputs "Pipe:" + input string. Note: we have a output.txt that contains "huh"
- Entered
echo "hi" | ./testPipe-> correctly printed "Pipe: hi" - Entered
cat output.txt | ./testPipein batch and interactive mode -> correctly printedPipe: huh
Note: we have a output.txt that contains "huh"
- Entered
echo hopefully made new file > newFile.txt-> correctly made a new file named "newFile.txt" and in it had the texthopefully made new file- tested that the output redirection works and that a new file is created if doesn't exist containing the content that was outputted on the left side of the >
- Entered
./testPipe < output.txt-> correctly printed "Pipe: huh"- tested that the input redirection works
- Entered
./testPipe < this_file_doesnt_exist.txt-> correctly reports error that it failed to open file and exited- if mysh is unable to open file in redirection, it will report an error and exit
Note: We have a directory named testDir, which contains text files and a subdirectory named testSubSub
- Entered
ls-> correctly listed all the files and directories in the project.- tested to see that ls correctly listed all the files and directories in the working directory
- Entered
pwd-> correctly printed the path to the current directory- tested to see that pwd prints the right path to the current directory
- Entered
cd testDirand thenpwd-> correctly printed the path to the testDir directory- test to see that cd successfully changes the working directory to the sub directory
- tested to see that pwd prints the path to the sub directory
- Entered
ls-> correctly listed all the files and directories in testDir.- tested to see that ls correctly listed all the files and directories in the working directory
- Entered
cd testDir testSub-> correctly prints an error "cd: wrong number of arguments"- cd only expects one argument, so there should be error if more than one
- Entered
cd dir_that_doesnt_exist-> correctly prints an error "cd: No such file or directory"- tested to see that cd gives an error when given a non-existent file/directory
- Entered
which gcc-> correctly printed the path to the gcc program (/us/bin/gcc)- tested to see that
whichonly accepts to print an existing program
- tested to see that
- Entered
which ls-> correctly exited and nothing printed- tested to see that
whichfails and prints nothing when given a name of a built-in command
- tested to see that
- Entered
which blahbahand blahblah isn't an existing program -> correctly exited and nothing printed- tested to see that
whichfails and prints nothing when given a non-existent program
- tested to see that
- Entered
which gcc gcc-> correctly exited and nothing printed- tested to see that
whichfails and prints nothing when given more than more argument
- tested to see that
- Entered
exit-> correctly printed "Exiting my shell" and quit the shell.- tested to see that exits correctly exits with the exiting message without any extra arguments
- Entered
exit hi-> correctly printed "hi" and "Exiting my shell" and quit the shell.- tested to see that exits correct prints any arguments it receives, separated by spaces
- Entered
./testPipe < output.txt then echo hi-> correctly printed "Pipe: huh" then "hi"- Tested to see if then works if command executed successfully before then statement
- Entered
./testPipe < few.txt then echo hi(few.txt does not exist so the first condition fails) -> only printed "Failed to open input file: No such file or directory", and not "hi"- Tested to see if then works if command failed successfully before then statement
- Entered
./testPipe < wfewfwf.txt else echo hi(wfewfwf.txt does not exist so the first condition fails) -> prints "hi" only - Tested to see if else works if command failed successfully before then statement