Professional Documents
Culture Documents
Os Prac Solution
Os Prac Solution
if [ $# -eq 1 ]
then
echo enter string is $1
str=$1
echo $str > rev1
k=`head rev1 | wc -c`
z=$k
i=1
while [ $i -le $k ]
do
x=`cut -c $z rev1`
if [ $i -eq 1 ]
then
rev=$x
C. U. Shah College Of Engineering & Technology
B.E- IVth CE/IT (Operating System)(140702)
PRACTICAL_SOLUTION_2010
else
rev=$rev$x
fi
i=`expr $i + 1`
z=`expr $z - 1`
done
if [ "$str" = "$rev" ]
then
echo string is palindrome
else
echo string is not
fi
else
echo enter the string
fi
echo enter no
read n
while [ $n -ne 1 ]
do
n3=`expr $n % 2`
if [ $n3 -eq 0 ]
then
n=`expr $n / 2`
echo -n $n ","
else
n=`expr $n \* 3 + 1`
echo -n $n ","
fi
done
if [ $# -eq 1 ]
then
echo “1.Append to file ”
echo “2.overwrite file to second file”
1)
cat $1>>s
echo “file is copy to s with overwrite ”
cat s
;;
2)
cat $1>s
echo “file is copy to s ”
cat s
;;
*) echo “enter only 1 or 2”
;;
esac
else
echo “enter only one argument”
8. Write Shell script that will add two nos, which are supplied as
command line argument, and if this two nos are not given show error
and its usage?
if [ $# -ne 2 ]
then
echo "Usage - $0 x y"
echo " Where x and y are two nos for
which I will print sum"
exit 1
fi
echo "Sum of $1 and $2 is `expr $1 + $2`"
C. U. Shah College Of Engineering & Technology
B.E- IVth CE/IT (Operating System)(140702)
PRACTICAL_SOLUTION_2010
if [ $# = 1 ]
then
sum=0
n=$1
while [ $n -ne 0 ]
do
sum=$((n+sum))
n=$((n-1))
done
echo "sum=$sum"
else
sum=0
r=50
while [ $r -ne 0 ]
do
sum=$((r+sum))
r=$((r-1))
done
echo "sum=$sum"
fi
C. U. Shah College Of Engineering & Technology
B.E- IVth CE/IT (Operating System)(140702)
PRACTICAL_SOLUTION_2010
10. Write a shell script to accept one or more filename and convert its
content to upper case.
for file in $*
do
tr '[a-z]' '[A-Z]' <$file
done
C. U. Shah College Of Engineering & Technology
B.E- IVth CE/IT (Operating System)(140702)
PRACTICAL_SOLUTION_2010
11. Write script to determine whether given file exist or not, file name is
supplied as command line argument, also check for sufficient number of
command line argument.
if [ $# -ne 1 ]
then
echo "Usage - $0 file-name"
exit 1
fi
if [ -f $1 ]
then
echo "$1 file exist"
else
echo "Sorry, $1 file does not exist"
fi