C, C++, UNIX Shell Scripts, Data Structure, Numerical Method and Statistical Technique and Computer Graphics' Lab Practical Programs For B.tech(CS & IT) , BCA , MCA , MSc(CS), B.Sc(CS) Students
Showing posts with label UNIX Shell Scripts. Show all posts
Showing posts with label UNIX Shell Scripts. Show all posts
Friday, 12 December 2014
Shell Script to Delete a directory
Write a Shell Script to Delete a directory
Solution:
Output:
Enter the name of the directory to be deleted
abc
Solution:
echo " Enter the name of the directory to be deleted"
read s
c=`ls $s | wc -l`
if test $c = 0
then
rmdir $s
else
rm -r $s
fi
Enter the name of the directory to be deleted
abc
Shell Script to list the contents of a directory
Write a Shell Script to list the contents of a directory
Solution:
Solution:
echo "Enter the name of the directory"
read d
ls $d
Shell Scripts to check for Prime numbers
Write a Shell Script to check whether a given number is Prime or not
Solution:
Solution:
Solution:
echo Enter any number
read num
b=`expr $num / 2`
if test $b -eq 1
then
echo It is a Prime number
fi
n=2
x=0
while [ $b -ge $n ]
do
c=`expr $num % $n`
if test $c -eq 0
then
echo Number is not prime
x=0
break
else
x=1
fi
n=`expr $n + 1`
done
if test $x -eq 1
then
echo It is a Prime number
fiShell Script for Palindrome number
Write a shell script to check whether a given number is palindrome or not
Solution:
Execution:
Solution:
echo Enter the number
read num
d=`expr $num`
c=0
while [ $d -gt 0 ]
do
b=`expr $d % 10`
d=`expr $d / 10`
c=`expr $c \* 10 + $b`
done
if test $num -eq $c
then
echo The Given number is Palindrome
else
echo The number is not a Palindrome
fiThursday, 11 December 2014
Shell Script to find the Reverse and Sum of a number
Write a Shell Script to find the Reverse and Sum of a the entered numbers
Solution:
Solution:
echo Enter any number
read n
rev=0
sd=0
sum=0
while [ $n -gt 0 ]
do
sd=`expr $n % 10`
rev=`expr $rev \* 10 + $sd`
sum=`expr $sum + $sd`
n=`expr $n / 10`
done
echo "Reverse number is $rev"
echo " sum of digits are $sum"
Execution:
Subscribe to:
Posts (Atom)





