Java Bash Shell
This project is a Shell Application that mimics a subset of Bash scripting capabilities in Java. This includes common Unix commands and salient features like redirection, substitution, sequence commands and piping. This project was completed for National University of Singapore's CS4218 Software Testing.
Getting Started
Prerequisites
Have Java 8 or later installed on your machine.
Installation
-
Clone the repo
git clone https://github.com/nicholas-gcc/java-bash-shell.git
-
Compile the project
javac -d bin src/main/java/sg/edu/nus/comp/cs4218/*.java src/main/java/sg/edu/nus/comp/cs4218/**/*.java
This command compiles all the Java files in the specified directories and saves the compiled bytecode files in the bin directory.
-
Run the entry point of the application
java -cp bin sg.edu.nus.comp.cs4218.impl.ShellImpl
Usage
Supported Features
-
Piping
echo "Hello, world!" | tee output.txt
-
I/O Redirection
cat file.txt | wc -l > line_count.txt
-
Sequence Commands
cp sample.txt new.txt; cut -c 6-7 new.txt
-
Command Substitution (With single quotation marks)
echo "'cat file.txt'"
-
Globbing
ls somePattern*
Commands
Command | Flags Supported |
---|---|
cat |
-n |
cd |
N/A |
cp |
-r, -R |
cut |
-b, -c |
echo |
N/A |
exit |
N/A |
grep |
-v,-i, -c, -H |
ls |
-R, -X |
mv |
-n |
paste |
-s |
rm |
-r, -d |
sort |
-n, -r, -f |
tee |
-a |
uniq |
-c, -d, -D |
wc |
-c, -l, -w |