Local and Global Variables
Local and Global Variables
#!/bin/bash
func()
echo $lvar
gvar="Global content
echo $gvar
echo $lvar
func
echo $gvar
echo $lvar
$ cat arithmetic.sh
#!/bin/bash
add=$(($x + $y))
sub=$(($x - $y))
mul=$(($x * $y))
div=$(($x / $y))
mod=$(($x % $y))
#!/bin/bash
let sum=0
for num in 1 2 3 4 5
do
done
echo $sum
#!/bin/bash
clear ; loop=y
while [ $loop = y ] ;
do
echo Menu
echo D: print the date
echo Q: quit.
echo
read choice
case $choice in
D | d) date ;;
W | w) who ;;
P | p) pwd ;;
Q | q) loop=n ;;
esac
echo
done
#!/bin/bash
clear
read user
if [ $c -gt 0 ]
then
else
echo "User is not logged in to the system"
fi
#!/bin/bash
clear
read n
i=0
while [ $i -le 10 ]
do
i=`expr $i + 1`
done
#!/bin/bash
clear
echo "Enter number1: "
read n1
echo "Enter operator(+, -, /, *): "
read op
echo "Enter number2:"
read n2
if [ "$op" = "+" ];
then
calc=`echo $n1 + $n2|bc`
echo "$n1 + $n2 = $calc"
elif [ "$op" = "-" ];
then
calc=`echo $n1 - $n2|bc`
echo "$n1 - $n2 = $calc"
elif [ "$op" = "*" ];
then
calc=`echo $n1 \* $n2|bc`
echo "$n1 * $n2 = $calc"
elif [ "$op" = "/" ];
then
calc=`echo $n1 / $n2|bc`
echo "$n1 / $n2 = $calc"
else
echo "Invalid operator!"
fi
#!/bin/bash
fact=1
echo -e "enter a number"
read n
if [ $n -le 0 ] ; then
echo "invalid number"
exit
fi
#factorial logic
if [ $n -gt 0 ] ; then
for((i=$n;i>=1;i--))
do
fact=`expr $fact \* $i`
done
fi
echo "The factorial of $n is $fact"