Skip to content

A basic alternative for bash with few cool custom commands to try out

License

Notifications You must be signed in to change notification settings

Arkadeep-sophoIITG/ruby-shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Rubyshell

===============

The Team

  • Arkadeep Das

    • Helmed the project, wrote the basic shell from scratch supporting all bash commands likecd , rm as listed below.
    • Designed and implemented job control feature in shell.
    • Implemented both the advanced features in the shell (rmp -e1 , rmp -e2 and <prog_name> m).
    • Implemented history n and issue n commands.
    • Lastly, made Readme.md and Makefile.
  • Arpan Gupta

    • Provided valuable insight regarding implementing basic features into the shell (commands like cat,exit).
    • Helped in building the documentation.
  • Rishabh Agrawal

    • Provided valuable insight regarding implementing basic features into the shell (commands like ls,exit).
    • Implemented history and issue n commands.

Software Requirements

  • GCC version 5.2.0 and upwards
  • The code is tested with gcc version 6.3.0

Note: Any lower version may result in underfined behaviour including compilation errors and memory corruptions.

Instructions to run the shell

  • Compile the source code using Makefile using the following command,

    make
    

    This should have created an executable called 'shell'

  • Run the shell using the following command,

    ./shell
    
  • To clean up the project, use the following command,

    make clean
    

Bash commands supported

  • ls
  • cd
    • cd <dir_name>
    • cd ..
    • cd /
    • cd ./dir_name
  • pwd
  • cat
  • cp
  • mv
  • find
  • mkdir
  • rm
    • rm -r <dir_name>
    • rm -f <file_name>
    • rm -i *
    • rm -v <file_name>
    • rm --help
  • history
    • retrieves history of all user commands.
  • history n
    • prints the most recent n commands issued by the numbers.
  • issue n
    • issues the nth command in the history once again.
  • <program_name>
    • Creates a child process to run <program_name>
  • Also supports Input/Output Redirection Operators < , > , >> , |
  • exit and all other basic bash commands.

Custom commands implemented

  • rmp (with -e1 and -e2 flags)
  • -e1
rmp -e1 extension

Deletes all files in directory except the files with the given extension.

  • -e2
rmp -e2 <list_of_files> 
Deletes all files in the current directory except those in the list. 
<program_name> m
<program_name> m creates a child process to execute program_name, but aborts the process if it does not complete its operation in m seconds by delivering proper message. 

Code walkthrough

Note: *Appropriate comments are used all throughout to enhance code readability*
  • The entire flow of the shell is controlled from function ruby_listener() which constantly listens for command-line input ,parses the input and sends it to executor() or calls appropriate functions to handle execution.

  • The executor(char *) function dispatches the command to any of the function execute(char *,char *) and execute_bg (char *,char *) or handles error in case process is non-existent.

  • Job control is implemented efficiently through is_fg(char *) is_bg(char *) [Note : these functions use Perl regex library which is deprecated and throws segmentation faults in few cases] , send_to_bg(int) and send_to_fg(int) functions.

  • Two user-defined structures are implemented proc_info (process structure) and history_info (history structure) along with pjid_list (process jobs list) and history_list (list of histories) along with many helper functions insert,search,update,clear and so on to perform appropriate tasks (as mentioned in the comments).

  • Ctrl+C (SIGINT signal) handler is implemented through custom_made_sigint_handler(int) .

  • Ctrl+Z (SIGTSTP signal) handler is implemented through custom_made_sigtstp_handler(int) .

  • History of user commands is retrieved through retrieve_all_histories(history_list *) , history n is implemented through print_n_histories(history_list *,char *) and issue n is implemented through retrieve_issue_cmd(history_list *,char *) .

Fallback Compilation Instructions if 'make' fails

NOTE: SKIP THIS SECTION IF make was successful i.e. if make did not throw errors.

  • Compile the source code using the following command,

    gcc minish.c -o shell
    

Bugs

  • regcomp() in regex.h: the regcomp() module is buggy as it "sometimes" results in malloc() error.
    Please note that IF THIS ERROR OCCURS WHILE TESTING, the shell source code does not contain any bugs.
    Its the library issue, as we believe the library is deprecated.
    Reason to use it was to detect the foreground and background commands.
    The approach of tokenization and detection may result in segmentation faults.
    For example: the following is a scenario that can result in a segmentation fault:

    minish>gcc test_sleep.c -o bin/test_sleep.o
    minish>ls
    segmentation fault
    

    Note that the segmentation fault occurs only when the -o option is used with the gcc command.
    This link has more information about this -- https://lists.ubuntu.com/archives/foundations-bugs/2012-May/089662.html

  • Continuing a suspended process in foreground works fine, but after the process completes
    execution it goes into an infinite loop. You will need to hit to get back the prompt.

References

  • Cornell CS414 Summer 2004 by Jeanna Matthews

Note: Please follow the instructions given in instructions.txt to view this Readme.md file

About

A basic alternative for bash with few cool custom commands to try out

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published