Friday 4 December 2015

Directory Handling-Bash Scripting


Q:- Write a menu driven script using bash programming to provide the user with the following facilities:-
  1. Create a new directory
  2. Delete a directory
  3. Display the file nodes
  4. Change the current working directory

 

Code

#!/bin/bash
Bash-script-file-handling
Bash Script 
echo "Program by Abhishek Munagekar"
echo "Program for directory operations"
while true
do
echo "enter your choice"
echo "1.create directory  2.remove directory 3.list file nodes 4.Change current directory 5.exit"
read choice
case $choice in
1)
echo "current state of the directory is"
dir
echo "enter name of new directory"
read newname
while [ -d $newname ]
do
echo "this directory already exsists, enter directory name again"
read newname
done
mkdir $newname
echo "new directory  $newname created successfully"
echo "now the directory contents are"
dir
;;
2)
echo "current directory contents are"
dir
echo "enter the name of the directory to remove"
read deldir
if [ -d $deldir ]
then
rm -r $deldir
echo "current state of the folder is "
dir
else
echo "incorrect directory name redirecting to earliear menu"
fi
;;
3)
echo "displaying node details of files of current folder"
ls -i
;;
4)
echo "give the path name"
read path
cd path
echo "current working directory is"
echo `pwd`
;;
5)
echo "terminating script"
break
;;
*)
echo "invalid choice, please enter values between 1 and 4 only"
;;
esac
done
Bash-script-file-handling
Bash Script



Related Posts

No comments:

Post a Comment