Q:- Write a menu driven script using bash programming to provide the user with the following facilities:-
- Create a new directory
- Delete a directory
- Display the file nodes
- 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 |
Related Posts
No comments:
Post a Comment