$ echo "Program for swapping two numbers: "
Program for swapping two numbers:
~$ a=2
~$ b=3
~$ c=$a
~$ a=$b
~$ b=$c
~$ echo "Numbers after swapping: "
Numbers after swapping:
~$ echo "a= $a"
a= 3
~$ echo "b= $b"
b= 2
$ echo "Program for even odd numbers :"
Program for even odd numbers :
$ read n
28
~$ if [ $((n % 2)) -eq 0 ];
>then echo "$n is even";
> else echo "$n is odd";
>fi
28 is even
echo " Program for factorial :"
Program for factorial :
~$ num=7
~$ factorial=1
~$ counter=$num
~$ while [[ $counter -gt 0 ]] ;
>do factorial=$(($factorial * $counter));
> counter=$(($counter-1)); done
~$ echo "factorial=$factorial"
factorial=5040
~$ echo "Progeam for fibonacci series :"
Progeam for fibonacci series :
~$ a=1
~$ b=2
~$ n=7
~$ for (( i=0; i<n; i++ )); do echo -n "$a ";
> fn=$((a + b)); a=$b; b=$fn; done
1 2 3 5 8 13 21