Your Only Destination To Empower Your Computer Programing Knowledge. Sky is not so high, You can Touch it if You Try

Script to show the case control structure

echo enter number
read a
echo
while [ $a -eq 1 ]
do
echo choices are:-
echo 1. To copy the files
echo 2. To show list of files
echo 3. To show use of head
echo *. Exit
echo
echo enter the choice
read ch
case $ch in
1) echo enter the source and target file
read a b
if cp $a $b
then
echo file copied successfully
fi
;;
echo
2) echo list of files with permission:-
ls -l
;;
echo
3) echo Enter the file
read k
echo Showing the 10 lines of files
head $k
;;
echo
*) exit ;;
esac
done

Output:-


enter number
1

choices are:-
1. To copy the files
2. To show list of files
3. To show use of head
*. Exit

enter the choice
2

list of files with permission:-
total 686
-rw-r--r-- 1 root root 0 Mar 20 14:51 ?[?1049l?
-rw-r--r-- 1 root root 0 Mar 20 14:51 ?[?12l?[?25h?[?1049l?]0
-rw-r--r-- 1 root root 55 Apr 6 15:44 2713
-rw-r--r-- 1 root root 0 Mar 21 15:13 2744
-rw-r--r-- 1 root root 0 Mar 21 15:06 2912
-rw-r--r-- 1 root root 0 Mar 21 15:07 2921
-rw-r--r-- 1 root root 0 Mar 21 15:10 2935
-rw-r--r-- 1 root root 52 Mar 30 15:15 3gt
-rw------- 1 root root 729 Feb 21 15:13 anaconda-ks.cfg
-rw-r--r-- 1 root root 23 Mar 21 14:24 anand1
-rw-r--r-- 1 root root 90 Apr 4 15:17 asd
-rw-r--r-- 1 root root 449 Apr 4 16:00 awk
-rw-r--r-- 1 root root 6 Feb 22 14:23 cmd
-rw-r--r-- 1 root root 0 Feb 27 15:06 cmdfile
-rw-r--r-- 1 root root 0 Feb 22 14:24 com
-rw-r--r-- 1 root root 469 Apr 6 15:31 database
drwxr-xr-x 3 root root 4096 Apr 10 16:25 Desktop
-rw-r--r-- 1 root root 69 Mar 16 14:45 emp.lst
-rw-r--r-- 1 root root 23 Mar 19 14:20 emp.txt
-rw-r--r-- 1 root root 18 Feb 22 14:14 end
-rw-r--r-- 1 root root 214 Mar 30 15:42 even
-rw-r--r-- 1 root root 30 Mar 1 14:49 govind
-rw-r--r-- 1 root root 557 Apr 10 15:56 grep
drwxr-xr-x 4 root root 4096 Mar 14 14:47 heena
-rw-r--r-- 1 root root 105 Mar 30 15:13 if
-rw-r--r-- 1 root root 29101 Feb 21 15:13 install.log
-rw-r--r-- 1 root root 0 Feb 21 14:57 install.log.syslog
-rw-r--r-- 1 root root 153 Feb 28 14:43 jyoti
-rw-r--r-- 1 root root 30 Mar 1 14:59 kanha
-rw-r--r-- 1 root root 164 Mar 1 14:21 kanhaiya
-rw-r--r-- 1 root root 0 Feb 28 14:21 keeru
-rw-r--r-- 1 root root 30 Mar 1 14:29 keshav
-rw-r--r-- 1 root root 30 Mar 1 14:48 madhav
-rw-r--r-- 1 root root 19 Mar 13 14:25 main
-rw-r--r-- 1 root root 30 Apr 11 15:29 meenu
-rw-r--r-- 1 root root 12 Mar 20 15:05 nav
-rw-r--r-- 1 root root 80 Feb 28 14:40 neelam
-rw-r--r-- 1 root root 34 Feb 22 14:13 pa
-rw-r--r-- 1 root root 27 Mar 13 14:25 pai
-rw-r--r-- 1 root root 34 Apr 3 15:15 radhe
-rw-r--r-- 1 root root 34 Apr 11 15:13 radhika
-rw-r--r-- 1 root root 12 Mar 13 14:26 rain
-rw-r--r-- 1 root root 20 Apr 5 15:08 result
-rw-r--r-- 1 root root 188416 Mar 21 15:13 wc.sh
-rw-r--r-- 1 root root 379 Apr 10 16:27 sed
-rwx-w---x 1 root root 69632 Mar 20 15:19 sorting.sh
-rw-r--r-- 1 root root 185 Mar 19 14:52 stu.lst
-rw-r--r-- 1 root root 57 Mar 16 15:16 stu.txt
-rw-r--r-- 1 root root 59 Mar 30 14:37 sum
-rw-r--r-- 1 root root 540 Apr 11 15:26 switch
-rw-r--r-- 1 root root 216 Mar 21 14:37 wc


choices are:-
1. To copy the files
2. To show list of files
3. To show use of head
*. Exit

enter the choice
3

Enter the file
Database

Showing the 10 lines of files
Name |Age |salary |contact no.
Meenu |23 |40000 |7206297384
jyoti |20 |35000 |9813456782
mamta |21 |32000 |9017720166
kavita |22 |30000 |9014445623
neha |23 |34500 |8014465777
sanchi |24 |23000 |9014356278
nishtha |25 |24567 |7289786254
mohina |19 |45000 |9824568753
mohit |22 |43000 |7013442455

choices are:-
1. To copy the files
2. To show list of files
3. To show use of head
*. Exit

enter the choice
7
[root@localhost ~]#

No comments:

Post a Comment