This project is the quarter assignment for UCR's CS100 class.
It contains two programs: rshell
and ls
.
rshell
is a command shell that is able to execute commands such as ls
and echo
. It prints the command prompt $
and then reads in commands in the following form:
cmd = executable [ argumentList ] [ connector cmd ] [ io_redir file ] [pipe cmd ]
connector = || or && or ;
io_redir = < or > or >>
pipe = |
where executable
is an executable program in the PATH
, argumentList
is an optional list of zero or more arguments for the executable that are separated by spaces, and file
is the name of a file.
Here, ;
, ||
, and &&
, as well as <
, >
, >>
, and |
work like they do in bash:
-
;
will always execute the command after it. -
&&
will execute the next command only if the previous command succeeded. -
||
will execute the next command only if the previous command failed. -
<
is input redirection that redirects stdin to the file after it. -
>
is output redirection that redirects stdout to overwrite or create the file after it. -
>>
is output redirection that redirects stdout to append to or create the file after it. -
|
is a pipe that takes the stdout of the cmd before it and redirects it as the stdin of the cmd after it.
For example, if you type in the following command:
$ ls -a; echo hello && mkdir test || echo world
then rshell
will execute the ls
command to print files in the current directory with the -a
flag.
Then it will print to the terminal hello
, and if that command succeeds, it will make a new directory called test
with the mkdir
command.
If either the echo hello
or mkdir test
commands failed, then the echo world
command will be executed.
Typing the connectors &&
and ||
at very end of command will result in error.
An example of the use of IO redirection and piping is
$ cat < existingInputFile | tr A-Z a-z | tee newOutputFile1 | tr a-z A-Z > newOutputFile2
Here, rshell
will execute the cat
command with the contents of existingInputFile
as its stdin.
Then it will pipe these contents to the tr
command, which will convert all the chars to lowercase letters.
This output is then piped to tee, which stores it in the file newOutputFile1
and then passes it along through the pipe to tr
. The text is then converted to all caps by tr
and finally is stored in the file newOutputFile2
.
rshell
also allows for the use of comments by typing in the #
character.
Anything after #
on a line will be ignored.
Another feature of rshell
is the cd
command, which allows you to change the current directory.
Usage is as follows:
cd directory
where directory
is either a relative or absolute pathname.
ls
is a program that lists the files in the current directory.
By passing in files and directories as arguments to ls
, you can also get the contents of a specific directory.
ls
also supports the use of the -a
, -R
, and -l
flags.
-
-a
will show the hidden files in a directory. -
`-R' will recursively list the contents of a directory and its subdirectories.
-
-l
will show the long listing format of the files in a directory.
The ls
program lastly will output directories in blue text, executables in green text, and hidden files with a gray background.
After cloning and downloading this repository, cd
into it and type make
in the command prompt. This will then make rshell
and ls
for you (requires the g++
compiler to be installed on your system).
If you wish to only make rshell
or only ls
, type make rshell
and make ls
respectively.
To run rshell
, type
$ bin/rshell
and this will launch the rshell
command prompt.
To exit rshell
, just type exit
.
To run ls
, type
$ bin/ls [args and flags]
and this will run ls
.
This also works while running rshell
.
Enjoy!
The program rshell
is only able to run executables located in /bin
or usr/bin/
like ls
, or in filepath the user specifies, but not common bash commands such as cd
.
Look for this feature to be coming soon!
Other bugs in rshell
:
-
Error messages for syntax errors with connectors are too general.
-
Commands typed before a
;
will run when not supposed to when certain syntax error occurs with&&
or||
. -
If you try to use
>>
to redirect output to a file that does not exist, it causes an error inopen
rather than create the file.
ls
has some bugs as well:
-
If you uncomment line 90 of
src/ls.cpp
, this causes the total block count to be displayed. The number shown is incorrect. Files get counted double the normal block count, and symbolic links add a number to the total block count, when their individual block count should be zero. -
This program cannot correctly identify symbolic links for the long listing format. It also displays the info for the file it is linked to, rather than itself.
-
If passed in a single bad file,
ls
defaults to printing files in current directory rather than just quitting.
If you find any bugs in this project, create an issue on GitHub, or, if you want, fix it yourself and issue a pull request.
Have fun and enjoy!