Logo 
Search:

Unix / Linux / Ubuntu Articles

Submit Article
Home » Articles » Unix / Linux / Ubuntu » Homework HelpRSS Feeds

Write a menu driven shell script for Copy a file, Remove a file, Move a file

Posted By: Mina Schmidt     Category: Unix / Linux / Ubuntu     Views: 34120

Write a menu driven shell script for

* Copy a file (user should specify source and target)
* Remove a file
* Move a file (take source and target)

Code for Write a menu driven shell script for Copy a file, Remove a file, Move a file in Unix / Linux / Ubuntu


    clear
        echo "Menu "
        echo "1. COpy a File "
        echo "2. Remove a file "
        echo "3. Move a file"
        echo "4. Quit"
        echo "Enter ur Choice \c"
        read Choice
        case"$Choice"in
           1) echo "Enter File name to copy \c"
              read f1
              echo "Enter FIle name \c "
          read f2         
          if [ -f $f1 ]
          then
                  cp $f1 $f2
              else
                     echo "$f1 does not exist"
              fi
              ;;
          2) echo "Enter the File to be removed "
             read r1
             if [ -f $r1 ]
             then      
                   rm -i $r1
             else 
                  echo "$r1 file does not exist "
             fi
             ;;
         3)
            echo "Enter File name to move \c"
            read f1
            echo "Enter destination \c "
            read f2
            if [ -f $f1 ]
             then 
                 if [ -d $f2 ]
                 then
                      mv $f1 $f2
                 fi
             else
                 echo "$f1 does not exist"
            fi
            ;;
         4) 
             echo "Exit......."
             exit;;
        esac

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

OUTPUT:
                                              
       $ sh38
         Menu
         1. COpy a File
     2. Remove a file
     3. Move a file
     4. Quit
        Enter ur Choice 1
        Enter File name to copy r1
        Enter FIle name r2
    $ sh38
     Menu
     1. COpy a File
     2. Remove a file
     3. Move a file
         4. Quit
            Enter ur Choice 3
        Enter File name to move r1
        Enter destination r3
    $ sh38
     Menu
     1. COpy a File
     2. Remove a file
     3. Move a file
         4. Quit
            Enter ur Choice 2
            Enter the File to be removed r1
         remove r1? y      
  
Share: 



Mina Schmidt
Mina Schmidt author of Write a menu driven shell script for Copy a file, Remove a file, Move a file is from Frankfurt, Germany.
 
View All Articles

 

Other Interesting Articles in Unix / Linux / Ubuntu:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!