Starting from:

$30

CSCE313-Assignment 3 Linux Shell Solved

For this assignment, you are to design a simple shell which implements a subset of the functionality of the Bourne Again Shell (Bash).        The requirements for your shell are as follows:

•    Continually prompt for textual user input on a command line.

•    Parse user input according the provided grammar (see below)

•    When a user enters a well formed command, execute it in the same way as a shell. You must use the commands fork and exec to accomplish this. You may NOT use the C++ system() command.

•    Allow users to pipe the standard output from one command to the input of another an arbitrary number of times.

•    Support input redirection from a file and output redirection to a file.

•    Allow users to specify whether the process will run in the background or foreground using an ’&’. Backgrounding processes should not result in the creation of zombie processes. (Commands to run in the foreground do not have an ’&’, and commands that run in the background do)

•    Print a custom prompt which supports printing the current directory, user name, current date, and current time.

•    (Bonus) Allowing $-sign expansion. See the last sample command in the list of commands for example.

Write a report describing your design for piping, redirection and other special techniques that you are unique to your implementation. No need to restate the obvious.

Figure #4: Simple Shell Grammar

valid string = unix command || unix command AMP || special command

unix command = command name ARGS  || unix command REDIRECTION filename ||
unix command PIPE unix command

special command = cd DIRECTORY || exit command name = any valid executable/interpreted file name

AMP = &

ARG = string

ARGS = ARG ARGS || ARG

DIRECTORY = absolute path || relative path

PIPE = |

REDIRECTION = < ||
Figure #4: Some Sample Commands

echo Here starts our shell ...

echo −e ‘‘<<<<< This message contains a line feed \n’’ echo ‘‘<<<<< Start to exercise pipe ’’

echo ‘‘<<<<< IO redirection ’’ ps test.txt
 

grep pts < test.txt pwd pwd.txt mv pwd.txt newpwd.txt cat newpwd.txt

echo ‘‘  1 pipe ’’ ps

echo ‘‘                        2 pipes ’’

psps −−aa || awk ’/pts/[0awk ’/pts/[0−−9]9]//{{print $1print $2}}’’ || tailtail

echo ‘‘<<<<< 3 pipes ’’

lslsls −−−l /proc/sysl /proc/sysl /proc/sys ||| awk ’awk ’awk ’{{{print $9print $8$9print $8}}’’ }’|||headsorthead−−−r310|||headsortsort −−r5

echo ‘‘<<<<< 4 pipes with I/O redirection ’’

awk ’cat output.txtls −l /proc/sys{print $8$9}’ test.txt< test.txt | head −10 | head −8 | head −7 | sort output.txt

echo ‘‘<<<<< Background process (ps after some time to make sure the bg’s are not defunct) ’’

dd if=/dev/zero of=/dev/null bs=1024 count=10485760 &

sleep 10 & ps

echo ‘‘<<<<< Directory Operations ’’ cd /home/ugrads/ pwd cd − pwd

echo ‘‘<<<<< Miscellenous ’’ rm newpwd.txt jobs

sleep 10

echo ‘‘cat /proc/$(ps<<<<<|grep bashBonus ($−|headsign expansion)−1|awk ’{print $1}’)/status’’

More products