I am trying to pass arg to this scripts but it does not work anyone knows how fix this ? and I do not want to use args i want to use getopts
For This part
# Get command line parameters
i=
a=
y=
while getopts iay: name
case $name in
i) i="$OPTARG" ;;
a) a="$OPTARG" ;;
y) y="$OPTARG" ;;
?) exit;;
esac
done
This is the scripts
if [ $# -ne 3 ]
then
echo -e "\nUsage: mortgage rate amount period\n"
exit 1
fi
# Get command line parameters
i=
a=
y=
while getopts iay: name
case $name in
i) i="$OPTARG" ;;
a) a="$OPTARG" ;;
y) y="$OPTARG" ;;
?) exit;;
esac
done
# Compute the monthly payment
x=$(echo "scale=20;1+$i/200" | bc)
z=$(echo "scale=20;1/6" | bc)
x2z=$(echo "scale=20;e($z*l($x))" | bc -l)
y12=$(echo "scale=20;-$y*12" | bc)
x2z2y12=$(echo "scale=20;e($y12*l($x2z))" | bc -l)
p=$(echo "scale=3;$a*(($x2z-1))/(1-$x2z2y12)" | bc)
# Print the monthly payment
echo $p
exit 0
========================== This is original scripts:
if [ $# -ne 3 ] then echo -e "\nUsage: mortgage rate amount period\n" exit 1 fi
Get command line parameters
i=$1; a=$2; y=$3
Compute the monthly payment
x=$(echo "scale=20;1+$i/200" | bc) z=$(echo "scale=20;1/6" | bc) x2z=$(echo "scale=20;e($z*l($x))" | bc -l) y12=$(echo "scale=20;-$y*12" | bc) x2z2y12=$(echo "scale=20;e($y12*l($x2z))" | bc -l) p=$(echo "scale=3;$a*(($x2z-1))/(1-$x2z2y12)" | bc)
Print the monthly payment
echo $p exit 0
it was like this :::::::::
if [ $# -ne 3 ] then echo -e "\nUsage: mortgage rate amount period\n" exit 1 fi
Get command line parameters
i=$1; a=$2; y=$3
Compute the monthly payment
x=$(echo "scale=20;1+$i/200" | bc) z=$(echo "scale=20;1/6" | bc) x2z=$(echo "scale=20;e($zl($x))" | bc -l) y12=$(echo "scale=20;-$y12" | bc) x2z2y12=$(echo "scale=20;e($y12l($x2z))" | bc -l) p=$(echo "scale=3;$a(($x2z-1))/(1-$x2z2y12)" | bc)
Print the monthly payment
echo $p exit 0
– Siavosh Bahman Oct 16 '15 at 00:53