Skip to main content

myshell


This is my linux shell program written in c. I will post a download link of the PDF of the code soon. :)

=============================================
INTRINSIC COMMANDS

cd - prints the current working directory.
cd <directory> - changes the current working directory to the specified. (e.g cd Videos)
echo - print rest of line as comment. (e.g echo helloworld)
environ - list the shell environment by having the built-in pointer: extern char **environ
pause - wait for the user to press ENTER key to continue
quit - quit the shell
help - print this help script


=============================================
ALIASES

clr - clear the screen
dir - list the contents of current working directory
dir <directory> - list the contents of <directory> (e.g dir Videos)


=============================================
I/O REDIRECTION
programname < inputfile - stdin is read from a file rather than the keyboard
programname > outputfile - stdout is redirected to outputfile. The file is automatically created if it does not exist, and truncated if it does which means that the previous content is overwritten.
(e.g sort > outfile)
programname >> outputfile - stdout is redirected to outputfile. The file is automatically created if it does not exist, and appended if it does which means that the output is appended to the last line of the file's contents.(e.g sort >> outfile)
command < inputfile > outputfile - read from inputfile, execute the program/command and truncate the output to outputfile.
command < inputfile >> outputfile - read from inputfile, execute the program/command and append the output to outputfile

===============================================
SCRIPT SUPPORT

The shell can read commands from a file when ./myshell batchfile is entered in the OS command prompt wherein batchfile is the filename of the script file. The script must be on the current working directory otherwise the execution will fail. To run in CLI remove the batchfile, simply enter ./myshell in OS cmd prompt.

===============================================
BACKGROUND EXECUTION

An ampersand (&) at the end of command line will make the shell return to the command line prompt immediately after launching that program. (e.g programname &). By default, commands are executed in the foreground. After one background execution, it will revert to foreground execution.


===============================================
ENVIRONMENT VARIABLES used in this shell

PWD - contains the full pathname of the current working directory. The value can be changed when a user invokes the cd
<directory> command
command
SHELL - contains the full pathname of the myshell. At the instant that myshell is opened the SHELL environment is changed
PARENT - the programs are executed with the PARENT environment containing the full pathname of myshell



I used this program as framework or backbone of myshell: shell.c

-------------------------------------------------------------------------------------------------------

*UPDATE download link of the code in pdf is now available  (07-31-10)
Download

Preview

Comments