Question

In: Computer Science

Write a BASH shell script (see the Important Notes section) that acts as a DOS command...

  1. Write a BASH shell script (see the Important Notes section) that acts as a DOS command interpreter (the user enters the DOS command and the script executes the corresponding Linux command).
    • The script should loop continuously until the user enters the QUIT command
    • Prior to accepting a command, display a prompt containing your first name and the greater than symbol (>)
      • Example prompt: linux>
    • The DOS command, and any arguments, should be stored in variables
      • $command – the DOS command (required)
      • $arg1 – the first argument (optional)
      • $arg2 – the second argument (optional)
        Note: Only some DOS/Linux commands will require one or both argument variables.
    • The script should use case statements to select the appropriate Linux command
      • If an unknown DOS command is entered, display the error message, Command Not Found!
  2. Refer to the table below for a list of DOS commands and their Linux counterparts (COMMAND [ARG 1] [ARG 2])
  1. DOS Command * Linux Command
    CHDIR [target directory] cd [target directory]
    CLS clear
    COPY [source file] [destination file] cp [source file] [destination file]
    CREATEDIR [directory name] mkdir [directory name]
    CREATEFILE [file name] touch [file name]
    DELETE [file name] rm [file name]
    DIR [file name | directory name | wildcard] ls [file name | directory name | wildcard]
    MOVE [source] [destination] mv [source] [destination]
    PRINT [message to print] echo [message to print]
    QUIT N/A
    RENAME [old name] [new name] mv [old name] [new name]
    TYPE [file name] cat [file name]
    * Assume DOS commands are case-insensitive (i.e., DIR is the same as dir).

Solutions

Expert Solution

#!/bin/bash
quit="quit"

echo -n "Linux> "
read comm
command1=`echo $comm | tr '[:upper:]' '[:lower:]'`

while [ "$command1" != "$quit" ]
do

echo "Linux> "
read comm

arg1=$1
arg2=$2

command1=`echo $comm | tr '[:upper:]' '[:lower:]'`

case $command1 in

chdir)
echo "chdir"
if [ $arg1 -eq "" ]
then
   echo "Please provide direcory name in argument"
else
   cd $arg1
fi
;;

cls)
echo "cls"
clear
;;

copy)
echo "Copy"
if [ $arg1 -eq "" ] && [ $arg2 -eq "" ]
then
   echo "Please provide arg1 and arg2 for source and destination filename"
else
   cp $arg1 $arg2
fi
;;

createdir)
echo "Create dir"
if [ $arg1 -eq "" ]
then
   echo "Please provide direcory name in argument"
else
   mkdir $arg1
fi
;;

createfile)
echo "Create file"
if [ $arg1 -eq "" ]
then
   echo "Please provide file name in argument"
else
   touch $arg1
fi
;;

delete)
echo "Delete"
if [ $arg1 -eq "" ]
then
   echo "Please provide file/directory name in argument to remove."
else
   rm -rf $arg1
fi
;;

dir)
echo "Dir"
;;

move)
echo "Move"
;;

print)
echo "Print"
if [ $arg1 -eq "" ]
then
   echo "Please provide argument to display message."
else
   echo $arg1
fi
;;

type)
echo "Type"
if [ $arg1 -eq "" ]
then
   echo "Please provide file name in argument to display content."
else
   cat $arg1
fi
;;

quit|QUIT)
   exit
;;
*)
echo -n "Command Not Found!"
;;
esac

done

if you have any doubt then please ask me without any hesitation in the comment section below , if you like my answer then please thumbs up for the answer , before giving thumbs down please discuss the question it may possible that we may understand the question different way and we can edit and change the answers if you argue, thanks :)


Related Solutions

this is bash scripting. a. Write a shell script that adds an extension “.deb” to all...
this is bash scripting. a. Write a shell script that adds an extension “.deb” to all the files in a directory. b. Write a command sequence or a script to insert a line “GHIJKLM” at every 10th line of a file? c. Write a bash command or script to find all the files modified in less than 5 days and print the record count of each.
Simple shell scripting Write a Bash shell script called strcount.sh that counts the number of occurances...
Simple shell scripting Write a Bash shell script called strcount.sh that counts the number of occurances of a given string within a file. The scripts takes two arguments: the name of the file to check and the string to count occurances of. If the file is not found (or not readable), the script should print the error message Cannot access file and exit with code -1. Otherwise, the script should print the number of occurances of the given string and...
write a bash shell script using the for-loop construct that counts the number of files and...
write a bash shell script using the for-loop construct that counts the number of files and directories looping through the files in the directory name provided by the user on a prompt by the script and prints "TOO many files" is the count of files is larger than a random number it generates between 20 and 40
Fully Functional Script written in BASH In this section, you will write a fully functional script...
Fully Functional Script written in BASH In this section, you will write a fully functional script to help your manager with an important project that will build upon what you learned from your script work in Milestone Four. After you have written the script, you will execute it to generate a report for all three users (once for Bob, once for Henry, and once for Frank). You should have three unique generated reports in your ~/scripts directory (or more if...
UNIX ONLY Write a bash script that will accept a filename as a command line argument....
UNIX ONLY Write a bash script that will accept a filename as a command line argument. Your script should first check whether the filename has been passed as argument or not (hint: at least one argument has to be provided). If no argument has been provided your script should display appropriate message and exit. If a file name has been provided, your script should check if the file exists in the current directory and display the contents of the file....
Write a bash shell script that takes exactly one argument, a file name. If the number...
Write a bash shell script that takes exactly one argument, a file name. If the number of arguments is more or less than one, print a usage message. If the argument is not a file name, print another message. For the given file, print on the screen its content.
Linux Sign into your lab account Write a bash shell script that does the following: Print...
Linux Sign into your lab account Write a bash shell script that does the following: Print out a friendly welcome message Ask the user for the name of their favorite animal Grep that animal from a text file noises.txt Tell the user what that animal says (i.e. what noise does it make) If the animal does not exist ask the user what noise the animal makes Store that new information in noises.txt
Part 2 – Scripting Goals:  Write a bash script  Use linux shell commands within...
Part 2 – Scripting Goals:  Write a bash script  Use linux shell commands within your script  Provide user feedback  Use loops  Use conditionals Remember to use chmod +x to make your file executable! Each script is 5 points in the Specifications portion of the rubric. Don’t forget to maintain good standards and comments. Script 1 – Echo-back some information Write a script name hello.sh that will take the user’s first name as a command line...
LINUX In Linux command line write a shell script ex1.sh that uses IF THEN to Prompt...
LINUX In Linux command line write a shell script ex1.sh that uses IF THEN to Prompt the user to "Enter a number between 1 and 10". (Hint: Use the 'echo' and 'read' commands in the script. See the slide about the 'read' command) If the number is less than 5, print "The number is less than 5" (Hint: You will read input into a variable; e.g. read NUM. In the IF statement, enclose $NUM in quotes; e.g. "$NUM". Also, remember...
write a bash shell program named L1 as follows . L1 expects exactly 2 command line...
write a bash shell program named L1 as follows . L1 expects exactly 2 command line arguments. expects $1 to contain only digits. expects $2 to have exactly 4 characters (can be any character). if NOT exactly 2 command line arguments, echo "need 2 args " and exit. otherwise, if $1 and/or $2 have incorrect value(s) (as above), echo "bad argX", where X is the first incorrect argument, and exit. otherwise, echo "good ". you can use echo,grep, pipe to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT