Looking for a program to undersand the goal and all the specifiaction mentioned
ID: 671316 • Letter: L
Question
Looking for a program to undersand the goal and all the specifiaction mentioned below.
Goal : Create a command-interpreter that will accept a few dos-like commands but execute in the unix style.
Commands that should be supported - most of unix commands such as grep, clear, ps, in addition we will support some dos commands listed under point 2 of specifications.
Specifications.
1. Like the dos environment the prompt should be the path of the current directory. (Unix system call -
getcwd - find the name of the current working directory).
2. The program should support the following DOS command(unix equvalent).
Implement switches in the program.
Accept commands like Dos and Unix.
DOS Unix
dir ls
del rm
copy cp
move/rename mv
type cat
cd cd
more < file more file
md mkdir
rd rmdir
cls clear
3. When executing these commands the program should fork a process and use execvp to execute the commands.
4. Redirection (< and >) should work as intended on the Unix system.
5. Unlike dos, the program should support running the process in the background using the ampersand sign (&). This means that the prompt will be printed and the command-interpreter will wait for the next command before the previous commands is completely executed when & is used following the command.
6. The program should also implement the pipe. A pipe (|) enables you to pass the output of the command on the left of the pipe as the input to the command on the right of the pipe.
Explanation / Answer
to fond host amne $ hostname Zeds-MacBook-Pro.local $ to find the current dorectory in dos prompt: DIR [drive:][path][filename] [/P] [/W] [/A[[:]attributes]] [/O[[:]sortorder]] [/S] [/B] [/L] [/V] [drive:][path][filename] Specifies drive, directory, and/or files to list. /P Pauses after each screenful of information. /W Uses wide list format. /A displays only files with these attributes: D Directories R Read-only files H Hidden files A Files ready for archiving S System files - Prefix meaning not: can be added to above attributes /O List by files in sorted order, sortorder: N By name (alphabetic) S By size (smallest first) E By extension (alphabetic) D By date & time (earliest first) G Group directories first A By Last Access Date (earliest first) - Prefix to reverse order: put in front of above /S Displays files in specified directory and all subdirectories. /B Uses bare format (no heading information or summary). /L Uses lowercase. /V Verbose mode. #!/bin/sh # DOS interpreter. Impersonates DOS as follows: # DOS command UNIX equivalent Action # cd cd Change directory # dir ls List directory contents # type cat List file contents # del rm Delete a file # ren mv Rename a file # copy cp Copy a file echo "Welcome to the DOS interpreter" echo "Type Ctrl-C to exit" # Infinite loop while [ "forever" ] do # Show DOS prompt; c stops a new line from being issued echo "DOS> c" # Read in user's command read command arg1 arg2 # Do a UNIX command corresponding to the DOS command case $command in cd) cd $arg1 ;; dir) ls ;; type) cat $arg1 ;; del) rm $arg1 ;; ren) mv $arg1 $arg2 ;; copy) cp $arg1 $arg2 ;; *) echo "DOS does not recognise the command $command" ;; esac done
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.