#Write an interactive file handling shell program.

Let it offer the user the #choice of copying ,removing ,renaming or linking files. Once the use has #made a choice, have the program ask the user for necessary information, #such as the file name ,new name and so on. echo "MENU" echo "1.FILE COPYING" echo "2.FILE RENAMING" echo "3.FILE REMOVING" echo "4.FILE LINKING" echo "ENTER YOUR CHOICE" set choice = $< switch ($choice) case 1: echo "enter the source file name" set source = $< echo "enter the target file name" set target = $< if( -f $source ) then cp $source $target echo "file copied successfully" else echo "source file doesnot exist" endif breaksw case 2: echo "enter the source file to rename" set source = $< echo "enter the new name for the source file" set target = $< mv $source $target echo "file renamed succeessfully" breaksw case 3: echo "enter the source file to remove" set source = $< rm $source echo "file removed successfully" breaksw case 4: echo "enter the source file to provide link" set source = $< echo "enter the link name for the source file" set target = $< link $source $target echo "file linked successfully" breaksw echo "file linked succeessfully" breaksw deefault: echo " you entered wrong choice" endsw /////////////////////// #Shell Script read two file names. Check weather two file contents are same or n ot . if same second file should be delete echo " Enter first file name" read f1 echo " enter 2nd file name" read f2 d=`cmp $f1 $f2` d1=""

\(.Use the more command to check the contents of myfile2. who > myfile2 $more myfile2 Delete second character: sed "s/^\(.\)$/\1/" file1 Delete word before last word: sed "s/ *[^ ]*\( *[^ ]*\)$/\1/" file1 . $echo . Use the date and who commands in sequence ?(in one line) such that the output of date will display on the screen and the output of who will be redirected to a file called my file2. f. c. b. log in the system b. $echo .the login shell is $0.if [ $d -eq $d1 ] then echo " Two files are similar and $f2 is deleted" rm $f2 else echo "Two file are different" fi ///////////////////// #Write a shell script that displays a list of all files in the current directory #to which the user has read write and execute permissions ls read -p "Enter a file name : " fn if test -f $fn then echo "The contents of the file $fn is :" cat $fn echo "No. e.\). use the who command redirect the result to a file called myfile1.Use the more command to see the contents of myfile1. $date . g. f. d./\1/" file1 Delete character before last character: sed "s/. of Characters: `wc -c $fn`" else echo "$fn is not exists or not a file" fi //////////////////////////// #Shell Script for finds given number is even / odd echo "enter a number" read a z=`expr $a % 2` if [ $z -eq 0 ] then echo "The number is even" else echo "the number is odd" fi /////////////////////// . d. e.the login shell is $SHELL. of Words : `wc -w $fn`" echo "No. h. use the appropriate commands to determine ur login shell c. use the /etc/passwd file to verify the result of step b. write a sed command that deletes the character before the last character in each line in a file. of Line: `wc -l $fn`" echo "No. write a sed command that deletes the first character in each line in a file g.

.TO EXTRACT A SUBSTRING FROM AGIVEN STRING" print "2. # 1) To extract a sub string from a given string # 2) To find the length of a given string print "MENU" print "1. 2) print the length of the string $string is c=$(print $string|wc -c) .//////////////////////////// #Write a shell script that accepts two integers as its arguments and #computes the value of first number raised to the power of the second number set c = 1 set result = 1 while($c <= $argv[2]) @ result *= $argv[1] @ c = $c + 1 end echo "$argv[1] raised to the power of $argv[2]=$result" //////////////////////////// #a) Write a shell script that computes the gross salary of a employee according to the #following # 1) if basic salary is <1500 then HRA 10% of the basic and DA =90% of the bas ic # 2) if basic salary is >1500 then HRA 500 and DA =98% of the basic # The basic salary is entered interactively through the key board echo "Enter the Salary " read sal if [ $sal -le 1500 ] then da=`expr $sal \* 90 / 100` hra=`expr $sal \* 10 / 100` gsal=`expr $sal + $hra + $da` echo "gsal:=$gsal" elif [ $sal -gt 1500 ] then hra=500 da=`expr $sal \* 98 / 100` gsal=`expr $sal + $hra + $da` gross=`expr $sa + $da + $hra` echo "gsal:=$gsal" echo "grass:=$gross" fi ///////////////////// # Write a shell script to perform the following string operations.TO FIND THE LENGTH OF THE STRING" print "ENTER YOUR CHOICE" read choice print "enter a string" read string case $choice in 1) print "enter position1" read pos1 print "enter position2" read pos2 print "the extracted substring from $pos1 to $pos2 of $string is" print $string|cut -c$pos1-$pos2.

then echo " Write" fi if [ -x $n/$fn ]. then echo " files in directory $n are :\n" for fn in `ls $dn` do if [ -d $n/$fn ].1 End /////////////////////// #Write a shell script that displays a list of all files in the current directory #to which the user has read write and execute permissions echo " Enter a name" read n if [ -d $n ].provided they exits in the current directory set c = 1 set x = $#argv while( $x != 0) tr '[a-z]' '[A-Z]' <$argv[$c] @ c = $c + 1 @ x = $x ... then echo " Execute" fi done else echo "$n not exist" fi . then echo "$fn is directory" elif [ -f $n/$fn ].((ch=c-1)) print $ch number of characters.1 End /////////////////////////////// #Shell script that accepts one or more file name as a arguments and #converts all of thenm to uppercase.provided they exits in the current directory set c = 1 set x = $#argv while( $x != 0) tr '[a-z]' '[A-Z]' <$argv[$c] @ c = $c + 1 @ x = $x . esac /////////////////////////// #Shell script that accepts one or more file name as a arguments and #converts all of thenm to uppercase. *) print " wrong choice ". then echo "$fn is file" fi if [ -r $n/$fn ]. then echo " Read" fi if [ -w $n/$fn ].