Professional Documents
Culture Documents
Dumy
Dumy
Develop a shell script to print the username, current date & time, and current
directory.
#!/bin/bash
Ans:-
-----------------------------------------------------------------------------------
--------------------------------------------------------------------------
2.Write a shell script to print sum of all digit of a given number.For e.g. If no
is 123, sum of all its digit will be 1+2+3 = 6
#!/bin/bash.
Ans:-
sum=0
-----------------------------------------------------------------------------------
--------------------------------------------------------------------------
3.Develop a shell script to compare three numbers and print the largest. Give the
numbers from the
command line.
#!/bin/bash
Ans:-
-----------------------------------------------------------------------------------
--------------------------------------------------------------------------
7.Write a shell script called calculator using case structure, which takes
arguments from command
line eg., 2+3, 2*3 etc. and displays the result. It should perform the following
operations:
a.Addition
b.Subtraction
c.Multiplication
d.Division
#!/bin/bash
Ans:-
echo "---CALCULATOR---"
echo "CAUTION: USE SPACE IN BETWEEN OPERAND AND OPERATOR "
echo ""
echo "OPERAND"
echo "Press + for Addition"
echo "Press - for Subtraction"
echo "Press * for Multiplication"
echo "Press / for Division"
echo "Press ^ for Power"
echo ""
-----------------------------------------------------------------------------------
-------------------------------------------------------------------------
13.Write script to print given number in reverse order, for eg. If no is 123 it
must print as 321
#!/bin/bash
Ans:-
reversed=0
-----------------------------------------------------------------------------------
-------------------------------------------------------------------------
Ans:-
no=5
-----------------------------------------------------------------------------------
-------------------------------------------------------------------------
Ans:-
factz=1
for (( i=1;i<=number;i++))
do
factz=$((factz*i))
done