echo Enter any sentence
read a
echo
echo Words in given sentence are:-
for i in $a
do
echo $i
done
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"for" 8L, 94C
Output:-
Enter any sentence
Sky is not so high you can touch it if you try
Words in given sentence are:-
Sky
is
not
so
high
you
can
touch
it
if
you
try
Script to show use of if-else control structure
echo enter two numbers:-
read a
read b
echo
if [ $a -gt $b ]
then
echo a is greater
else
echo b is greater
fi
~
~
~
~
~
~
~
~
~
~
~
~
"if" 11L, 160C
Output:-
enter two numbers:-
12
11
a is greater
read a
read b
echo
if [ $a -gt $b ]
then
echo a is greater
else
echo b is greater
fi
~
~
~
~
~
~
~
~
~
~
~
~
"if" 11L, 160C
Output:-
enter two numbers:-
12
11
a is greater
Script to show the use of while loop.
echo Enter a number to print it's table
read n
i=1
while [ $i -lt 10 ]
do
i='expr$i*$n'
i='expr$i+1'
echo $i
done
~
~
~
~
~
~
~
~
~
~
"while" 13L, 158C
Output:-
Even numbers between 1-20 are:-
2
4
6
8
10
12
14
16
18
20
read n
i=1
while [ $i -lt 10 ]
do
i='expr$i*$n'
i='expr$i+1'
echo $i
done
~
~
~
~
~
~
~
~
~
~
"while" 13L, 158C
Output:-
Even numbers between 1-20 are:-
2
4
6
8
10
12
14
16
18
20
Subscribe to:
Posts (Atom)