Linux shell implementation
For compilation:
use the "make" command to compile the files.
Usage:
use the "./shell" command to run the shell.
Assumption and Errors:
-
If the user enters without typing any command, the program goes into an infinite loop.
-
File not found an error in the cat, rm.
-
If the user changes the current directory, then none of the external commands will work because the program searches for binary in the current folder.
-
Once the "history -c" command is used, "history" cannot be used to see history as history would clear by history clear command.
-
If the user types any command with leading space before the command, then the leading space would be ignored. E.g.: ' echo hello world.'
Commands and systems call used:
I have used the execvp() function from the execl() family system call to call the binaries of external commands. I have also used fork() and wait() system call to create child processes and to wait for the child program to terminate.
Command-line option :
- help command for documentation
Internal Commands :
-
cd = to change the current directory
-
history = show command history
-c : clear history4.echo = print arguments
-n : do not output the trailing newline
- echo = print arguments
-n : do not output the trailing newline
-
pwd = print working directory
-
exit = exit the shell
External Commands:
- ls = list directory contents
-a : show hidden files
- cat = open files
-b : show line number
- date = show date
-u : date in UTC
- rm = remove file
-v : verbose
- mkdir = make directories
-v : verbose
-m : make directory with permission
Other functions used:
-
mkdir - mkdir()
-
pwd - getcwd()
-
cd - chdir()
-
cat - fgetc()
-
ls - scandir()
-
date - time()
-
rm - remove()