Monday, 2 April 2018

Shell script to perform basic operations on file


#Performs file operations
echo "Enter your choice"
echo "1. Copy 2. Remove 3. Rename 4. Exit"
read choice
if [ $choice -eq 1 ]
then
    echo "Enter the filename to be copied"
    read f1
    echo "enter the target filename"
    read f2
    cp $f1 $f2
fi
if [ $choice -eq 2 ]
then
    echo "enter the filename to be removed"
    read f1
    rm $f1
fi
if [ $choice -eq 3 ]
then
    echo "enter the file name to be renamed"
    read f1
    echo "Enter the file name to replace"
    read f2
    mv $f1 $f2
fi
if [ $choice -eq 4 ]
then
    exit 1
fi


OUTPUT
csc@csc-SVE1513CYNB ~ $ sh fileOp.sh
Enter your choice
1. Copy 2. Remove 3. Rename 4. Exit
1
Enter the filename to be copied
fileOp.sh
enter the target filename
ss
csc@csc-SVE1513CYNB ~ $ sh fileOp.sh
Enter your choice
1. Copy 2. Remove 3. Rename 4. Exit
2
enter the filename to be removed
ss
csc@csc-SVE1513CYNB ~ $ sh fileOp.sh
Enter your choice
1. Copy 2. Remove 3. Rename 4. Exit
3
enter the file name to be renamed
fileOp.sh
Enter the file name to replace
fOperations.sh
csc@csc-SVE1513CYNB ~ $ sh fileOp.sh
Enter your choice
1. Copy 2. Remove 3. Rename 4. Exit
4